Array of function processing in C

I declared an array of functions as:

void * (thread_fun[100])(void *); 

But compilation fails:

error: declaration 'thread_fun as an array of functions void * (thread_fun []) (void *);

What is wrong with my declaration. And how can this be fixed. I want to create an array of functions in my program. Offer me a solution.

+5
source share
2 answers

Cannot declare an array of functions. You can only declare an array of pointers:

 void * (*thread_fun[100])(void *); 
+8
source

As a user of Zbynek Vyskovsky noted, you can only have an array of function pointers.

However, I would also recommend using typedef to facilitate handling of function pointers:

 typedef void* (*FunctionPtrType)(void*); // Define type FunctionPtrType thread_fun[100]; // Declare the array 
+1
source

Source: https://habr.com/ru/post/1242095/


All Articles