I have two functions, each of which takes a pointer to a different type:
void processA(A *);
void processB(B *);
Is there a type of function pointer that could hold a pointer to any function without casting? I tried to use
typedef void(*processor_t)(void*);
processor_t Ps[] = {processA, processB};
but this did not work (the compiler complains about incompatible initialization of the pointer).
Edit: another part of the code will go through the Ps entries without knowing the types. This code will pass char * as a parameter. Like this:
Ps[i](data_pointers[j]);
Edit: Thanks everyone. In the end, I will probably use something like this:
void processA(void*);
void processB(void*);
typedef void(*processor_t)(void*);
processor_t Ps[] = {processA, processB};
...
void processA(void *arg)
{
A *data = arg;
...
}
source
share