I've declared an array of functions as:
void * (thread_fun[100])(void *);
But, compilation is terminated with error:
error: declaration of ‘thread_fun’ as array of functions void * (thread_fun[])(void *);
What is wrong with my declaration. And, how it can be corrected. I want to create an array of function in my program. Suggest me a solution.
It's not possible to declare array of functions. You can only declare array of pointers to function:
void * (*thread_fun[100])(void *);
As user Zbynek Vyskovsky noted, you can only have array of function pointers.
However, I would also recommend that you use typedef
to make handling of function pointers easier:
typedef void* (*FunctionPtrType)(void*); // Define type
FunctionPtrType thread_fun[100]; // Declare the array
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With