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?
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
.