Return value of signal

梦想的初衷 提交于 2019-12-10 19:47:25

问题


I was reading about the signal function, the definition is:
void (*signal(int sig, void (*func)(int)))(int); and the return value is:

If the request can be honored, signal() shall return the value of func for the most recent call to signal() for the specified signal sig. Otherwise, SIG_ERR shall be returned and a positive value shall be stored in errno.

The doubt is: isn't signal a void function? Should it return nothing?


回答1:


The actual signal handler function is a function with void return. The function signal which installs new signal handles returns the previous signal handler function pointer.

The syntax of declaring function returning function pointers is pretty complex and hard to decipher (you really got to keep track of all those parentheses). It would have been easier if there was a typedef, like it's done in Linux (from the Linux signal manual page):

typedef void (*sighandler_t)(int);

sighandler_t signal(int signum, sighandler_t handler);

Also note that the signal function is considered deprecated in favor of sigaction.



来源:https://stackoverflow.com/questions/23076909/return-value-of-signal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!