gx1*_*x16 3 c parameters gcc arguments function
我对以下 C 函数 f_2() 感到困惑。它写在.c文件中,代码可以用gcc编译。这个函数样式的名称是什么?如何解释这个函数的含义呢?这是标准 C 还是某些 gcc 扩展?谢谢。
void f_1()
{
}
int (*f_2(void *param)) (int, void *) {
return 0;
}
int main()
{
f_2(NULL);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Som*_*ude 13
该函数f_2接受一个void *参数,并返回一个指向函数的指针。
返回的指针f_2是一个指向函数的指针,该函数接受两个参数( anint和 a void *)并返回 an int。
它相当于:
// 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;
}
Run Code Online (Sandbox Code Playgroud)