Linked Questions
14 questions linked to/from Function pointer cast to different signature
20 votes
4 answers
15k views
How to print the address of a function?
I let gcc compile the following example using -Wall -pedantic: #include <stdio.h> int main(void) { printf("main: %p\n", main); /* line 5 */ printf("main: %p\n", (void*) main); /* line 6 */ ...
4 votes
8 answers
7k views
What are the parameters in this C qsort function call?
qsort(bt->rw[t], bt->num[t], sizeof(TRELLIS_ATOM *), (int (*)(const void *,const void *))compare_wid); bt->rw[t] is a pointer to struct pointer, bt->[num] is an int, I don't ...
2 votes
2 answers
8k views
Cast a function pointer
Suppose I have a function void myFun(int*) In C++ what exactly does the following mean ( void(*)(void*) )&myFun Is it a pointer to a function that takes a (void*) as an argument and returns a ...
5 votes
2 answers
2k views
function pointers within a struct but with functions of different prototype in C
Suppose I have functions: void func1(int x) { .... } void func2(int x, int y) { .... } void func3(int x, int y, int z) { .... } And say that I want to have a function pointer within a ...
1 vote
3 answers
2k views
How do I declare a C++ prototype with a void * pointer so that it can take any pointer type?
I want to create a function prototype in C++ so that there is a void * argument that can take pointers of any type. I know that this is possible in C. Is it possible in C++? [EDIT] Here is a ...
2 votes
2 answers
2k views
Casting A Function Pointers Return Type in C
I have a back end function that returns a void pointer (void*) and I have several front end function pointers that point to it. Each front end function pointer however needs to return a different type ...
1 vote
2 answers
1k views
Function pointer signatures are not matching, still not facing any issues while executing the program
I am trying to analyze what happening to the extra or less parameters that are supplied to the function pointers which are not of compatible size (Less or more arguments). Consider the below example ...
6 votes
3 answers
500 views
Can you cast a pointer to a function of one type to a function of another type that takes additional arguments?
Can you cast a function pointer of this type: void (*one)(int a) to one of this type: void (*two)(int a, int b) and then safely invoke the pointed-to function with the additional arguments(s) it has ...
2 votes
2 answers
319 views
function pointer assignments
Why am I able to assign a function that returns an int with no parameters specified to a function pointer that returns an int but takes an int argument? For example when I do: int f() { return 0;} ...
2 votes
4 answers
212 views
Is it well defined to cast generic function pointers to specifc signatures with void* params pointing to different types
EDIT2: It seems that the standard is not exactly clear, and appears to at least partially contradict itself in different parts on the usage of void* or struct* when casting function pointers. The lack ...
3 votes
1 answer
195 views
How does casting and calling obj_msgSend() not invoke undefined behavior?
I observed the usage of objc_msgSend to send messages to Objective-C IDs from pure C. The usage is not well documented but I found an example here. What I am confused by is the function pointer is ...
1 vote
1 answer
246 views
Correct use of a generic function pointer
Given the following declaration for a function used to update a node in a doubly linked list: uint8 dl_update(DL_LIST **node, uint16 new_tag, void *new_object, uint32 new_size, void (*destructor)(...
1 vote
0 answers
259 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
2 answers
241 views
Checking if it's safe to cast a function pointer into another one
In my code I'm trying to use dummy objects to perform modularity in C. At the moment I specify important function useful for every objects via function pointers, like destructors, toString, equals as ...