How can I create a "function pointer" (and (for example) the function has parameters) in C?
相关问题
- Multiple sockets for clients to connect to
- Do the Java Integer and Double objects have unnece
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
I found this site helpful when I was first diving into function pointers.
http://www.newty.de/fpt/index.html
First declare a function pointer:
Almost the same as a function prototype.
But now all you've created is a type of function pointer (with
typedef
).So now you create a function pointer of that type:
Now assign function addresses to those, and you can use them like they're functions:
Function pointers are great fun.
Additionally, we can create array of pointers to function:
You can also define functions that return pointers to functions:
f is a function that takes a single int parameter and returns a pointer to a function that takes a double parameter and returns int.
http://www.newty.de/fpt/index.html