This isnt actually a function pointer - this is defining a function pointer type:
typedef struct patchwork *(*create_patchwork_value_fct)
(const enum nature_primitif);
So, this defines a function pointer type called create_patchwork_value_fct
. This is a function pointer to a function that takes a single parameter(const enum nature_primitif), and returns a struct patchwork*
- i.e. a pointer to a patchwork struct.
Lets look at how this could be used:
void someFunc(create_patchwork_value_fct funcToCall, enum param)
{
funcToCall(param);
}
struct patchwork* CreateAPatchworkValue(enum nature_primitif enumVal)
{
struct patchwork* pwork = malloc(sizeof(struct patchwork));
pwork->someVal = enumVal;
return pwork;
}
void main()
{
someFunc(CreateAPatchworkValue, <a valid nature_primitif enumeration value>)
}
in this example, main()
calls someFunc()
, passing it a pointer to CreateAPatchworkValue as the funcToCall
parameter, and a value from the nature_primitif enum.
someFunc then calls funcToCall, which is actually a call to CreateAPatchworkValue.