int (*fn_pointer ( this_args ))( this_args );
声明fn_pointer
为一个函数,它接受this_args
并返回一个指向以this_args
为参数且返回类型为int
的函数的指针。它相当于
typedef int (*func_ptr)(this_args);
func_ptr fn_pointer(this_args);
让我们更好地理解一下:
int f1(arg1, arg2); // f1 is a function that takes two arguments of type
// arg1 and arg2 and returns an int.
int *f2(arg1, arg2); // f2 is a function that takes two arguments of type
// arg1 and arg2 and returns a pointer to int.
int (*fp)(arg1, arg2); // fp is a pointer to a function that takes two arguments of type
// arg1 and arg2 and returns a pointer to int.
int f3(arg3, int (*fp)(arg1, arg2)); // f3 is a function that takes two arguments of
// type arg3 and a pointer to a function that
// takes two arguments of type arg1 and arg2 and
// returns an int.
int (*f4(arg3))(arg1, arg2); // f4 is a function that takes an arguments of type
// arg3 and returns a pointer to a function that takes two
// arguments of type arg1 and arg2 and returns an int
如何阅读int (*f4(arg3))(arg1, arg2);
f4 -- f4
f3( ) -- is a function
f3(arg3) -- taking an arg3 argument
*f3(arg3) -- returning a pointer
(*f3(arg3))( ) -- to a function
(*f3(arg3))(arg1, arg2) -- taking arg1 and arg2 parameter
int (*f3(arg3))(arg1, arg2) -- and returning an int
那么,最后有个家庭作业 :). 试着弄清楚这个声明。
void (*signal(int sig, void (*func)(int)))(int);
并使用 typedef
对其进行重新定义。