I’ve a little question.
I’m trying to define an array of function pointers dynamically with calloc.
But I don’t know how to write the syntax.
Thanks a lot.
I’ve a little question. I’m trying to define an array of function pointers dynamically
Share
The type of a function pointer is just like the function declaration, but with “(*)” in place of the function name. So a pointer to:
would be:
In order to name an instance of this type, put the name inside (*), after the star, so:
declares a variable called foo_ptr that points to a function of this type.
Arrays follow the normal C syntax of putting the brackets near the variable’s identifier, so:
declares a variable called foo_ptr_array which is an array of 2 function pointers.
The syntax can get pretty messy, so it’s often easier to make a typedef to the function pointer and then declare an array of those instead:
In either sample you can do things like:
Finally, you can dynamically allocate an array with either of:
Notice the extra * in the first line to declare a1 as a pointer to the function pointer.