156
votes
9answers
84k views

How do function pointers in C work?

I had some experience lately with function pointers in C. So going on with the tradition of answering your own questions, I decided to make a small summary of the very basics, for those who need a ...
21
votes
7answers
19k views

Casting a function pointer to another type

Let's say I have a function that accepts a void (*)(void*) function pointer for use as a callback: void do_stuff(void (*callback_fp)(void*), void* callback_arg); Now, if I have a function like ...
26
votes
4answers
5k views

How does dereferencing of a function pointer happen?

Why and how does dereferencing a function pointer just "do nothing"? This is what I am talking about: #include<stdio.h> void hello() { printf("hello"); } int main(void) { ...
37
votes
4answers
52k views

Using an array of function pointers?

how to use array of function pointers in c? how to initialize them?
5
votes
4answers
3k views

C function pointer casting to void pointer

I am trying to run the following program but getting some strange errors: File 1.c: typedef unsigned long (*FN_GET_VAL)(void); FN_GET_VAL gfnPtr; void setCallback(const void *fnPointer) { ...
22
votes
9answers
17k views

How to get function's name from function's pointer in C?

How to get function's name from function's pointer in C? Edit: The real case is: I'm writing a linux kernel module and I'm calling kernel functions. Some of these functions are pointers and I want to ...
27
votes
4answers
35k views

Understanding typedefs for function pointers in C: Examples, hints and tips, please

I have always been a bit stumped when I read other peoples' code which had typedefs for pointers to functions with arguments. I recall that it took me a while to get around to such a definition while ...
6
votes
5answers
2k views

What are the operations supported by raw pointer and function pointer in C/C++?

What are all operations supported by function pointer differs from raw pointer? Is > , < , <= , >=operators supported by raw pointers if so what is the use?
79
votes
12answers
5k views

Why are function pointers and data pointers incompatible in C/C++?

I have read that converting a function pointer to a data pointer and vice versa works on most platforms but is not guaranteed to work. Why is this the case? Shouldn't both be simply addresses into ...
15
votes
5answers
6k views

How to format a function pointer?

Is there any way to print a pointer to a function in ANSI C? Of course this means you have to cast the function pointer to void pointer, but it appears that's not possible?? #include <stdio.h> ...
8
votes
13answers
3k views

Get a pointer to the current function in C (gcc)?

is there a magic variable in gcc holding a pointer to the current function ? I would like to have a kind of table containing for each function pointer a set of information. I know there's a _func_ ...
10
votes
3answers
3k views

What is guaranteed about the size of a function pointer?

In C, I need to know the size of a struct, which has function pointers in it. Can I be guaranteed that on all platforms and architectures: the size of a void* is the same size as a function pointer? ...
7
votes
10answers
3k views

What are function pointers used for, and how would I use them?

I understand I can use pointers for functions. Can someone explain why one would use them, and how? Short example code would be very helpful to me.
3
votes
3answers
1k views

Cast member function for create_pthread() call

I want to stop the warning server.cpp:823: warning: converting from 'void* (ClientHandler::)()' to 'void ()(void)' in the call: pthread_create(th, NULL, (void* (*)(void*)) ...
11
votes
0answers
2k views

C: Why is casting from void pointer to function pointer undefined? [duplicate]

Possible Duplicate: Why are function pointers and data pointers incompatible in C/C++? In the man page for dlsym, the following snippet has been provided. double (*cosine)(double); ...

1 2 3 4
15 30 50 per page