use an example to indicate. given,
void (*signal(int sig, void (*func)(int)) ) (int);
(You call signal() and pass it arguments to say which interrupt you are talking about, and which routine should be invoked to handle it.)
firstly, drop the arguments of signal and this means,
void (*signal( ) ) (int);
and one funny argument is ,
void (*func)(int);
func is a pointer to a function taking an int argument and returning void.
here's how the signal can be simplified as follow,
typedef void (*ptr_to_func) (int);
/*
*this says that ptr_to_func is a pointer to a function
* that takes an int argument, and returns void
*/
ptr_to_func signal(int, ptr_to_func);
/*
*this says that signal is a function that takes
* two arguments, an int and a ptr_to_func, and
* returns a ptr_to_func
*/
博客通过示例介绍了signal函数。给出了signal函数原型,先去掉其参数,指出其中一个参数func是指向接受一个int参数并返回void的函数指针。最后展示了如何将signal函数简化,使用typedef定义指针类型,简化后的signal函数接受两个参数并返回一个指针类型。
603

被折叠的 条评论
为什么被折叠?



