I have following code:
typedef int (*t_Function) (int x);
t_Function Functions[MAX_FUNCTIONS];
int f(int x)
{
return 0;
}
But I cannot initialize it properly. If I add following line:
Functions[0] = f;
then compiler generates following error:
prog.c:217: warning: data definition has no type or storage class
prog.c:217: error: conflicting types for Functions
How to initialize this array of pointers to functions?
You should either do it inside a function, where
Functions[0] = f;works fine, or with an array initializer:For this to work,
f(and all functions you want inFunctions) must have been declared at the point where this definition appears. Note that all otherMAX_FUNCTIONS-1elements ofFunctionswill beNULLautomatically if at least one of them is filled this way.