Linked Questions
45 questions linked to/from Casting a function pointer to another type
6
votes
4answers
1k views
Is passing additional parameters through function pointer legal/defined in C? [duplicate]
Possible Duplicate:
Casting a function pointer to another type
Assume i initialize a function pointer with a function that actually takes less parameters then the function pointer definition, ...
1
vote
0answers
243 views
Is it legal to cast function pointers? [duplicate]
Possible Duplicate:
Casting a function pointer to another type
int primes[] = {11, 5, 3, 7, 19, 13, 2, 17};
int comp(const int*, const int*);
qsort(primes, 8, sizeof(int), (int(*)(const void*, ...
0
votes
0answers
87 views
Is casting a function pointer always undefined, or is it sometimes implementation defined? [duplicate]
I hope this is not a duplicate, if it is I apologize.
Edit: this is a duplicate, in the sense that a similar question has been asked before. The answers to that question don't quite fit. To get a ...
0
votes
0answers
39 views
Function pointer to function with argument of different pointer type. Undefined behaviour? [duplicate]
I couldn't quite find a definitive answer to this one. My function pointer points to two functions that both take a pointer as an argument. Pointers in the same program are all the same size. Is the ...
10
votes
8answers
3k views
What happens if I cast a function pointer, changing the number of parameters
I'm just beginning to wrap my head around function pointers in C. To understand how casting of function pointers works, I wrote the following program. It basically creates a function pointer to a ...
17
votes
7answers
23k views
Function pointer cast to different signature
I use a structure of function pointers to implement an interface for different backends. The signatures are very different, but the return values are almost all void, void * or int.
struct ...
15
votes
5answers
2k views
Casting function pointers
I am writing a function that receives a pointer to a comparison function and an array of MyStructs and is supposed to sort the array according to the comparison function:
void myStructSort(
...
7
votes
5answers
9k views
reinterpret_cast to void* not working with function pointers
I want to reinterpret cast a function pointer into a void* variable. The type of the function pointer will be of type Class* (*)(void*).
Below is the sample code,
class Test
{
int a;
};
int ...
4
votes
6answers
9k views
What does int (*ret)() = (int(*)())code mean?
Here is a copy of code from shellstorm:
#include <stdio.h>
/*
ipaddr 192.168.1.10 (c0a8010a)
port 31337 (7a69)
*/
#define IPADDR "\xc0\xa8\x01\x0a"
#define PORT "\x7a\x69"
unsigned char code[]...
6
votes
6answers
1k views
What does this C syntax mean?
This is from a 'magic' array library that I'm using.
void
sort(magic_list *l, int (*compare)(const void **a, const void **b))
{
qsort(l->list, l->num_used, sizeof(void*),
(int (*)(...
6
votes
3answers
7k views
Casting function pointers with different pointer types as an argument
The following code, I think, describes what I am trying to do. Specifically, I wish to cast a function pointer to a generic function type, with the only difference in signature being different pointer ...
3
votes
5answers
3k views
Callback in C++, template member? (2)
The following callback class is a generic wrapper to "callable things". I really like its API, which has no templates and is very clean, but under the hood there is some dynamic allocation which I was ...
9
votes
3answers
839 views
Is it safe to call a C function with more arguments than it expects?
I'm repeatedly bumping into the problem of setting up signal handlers in GTK+ code, not needing several of the parameters and tempted to use the same function as the handler for several signals, whose ...
6
votes
3answers
253 views
Passing `int (*)(char const*)` where `int (*)(char*)` is expected
I have a function pointer whose function is declared as expecting char * arguments.Into it, I'd like to save a pointer to a function declared as taking char const* arguments.
I guess I can either use ...
4
votes
2answers
1k views
Are void* pointer and pointer to some structure (layout-) compatible?
In other words, may I reinterpret (not convert!) void* pointer as a pointer to some structure type (assuming that the void* pointer really holds properly converted valid structure address)
Actually I'...