I am confused about following C function, f_2(). It is written in .c file, code can be compiled by gcc. What is the name of this function style? How to interpret the meaning of this function? Is this standard C or some gcc extension? Thanks.
void f_1()
{
}
int (*f_2(void *param)) (int, void *) {
return 0;
}
int main()
{
f_2(NULL);
return 0;
}
>Solution :
The function f_2 takes a void * arguments, and returns a pointer to a function.
The pointer that f_2 returns is a pointer to a function that takes two arguments (an int and a void *) and returns an int.
It’s equivalent to:
// Create a type-alias for a function pointer
typedef int (*function_pointer_type)(int, void *);
// Define a function that returns a pointer to a function
function_pointer_type f_2(void *)
{
return NULL;
}