Sundeep KOKKONDA
Sundeep KOKKONDA

Reputation: 99

Array of functions handling in C

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.

Upvotes: 5

Views: 128

Answers (2)

user694733
user694733

Reputation: 16043

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

Upvotes: 1

Zbynek Vyskovsky - kvr000
Zbynek Vyskovsky - kvr000

Reputation: 18825

It's not possible to declare array of functions. You can only declare array of pointers to function:

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

Upvotes: 8

Related Questions