In signal.h there is declaration of signal function:
void (*signal(int signo, void (*func)(int))) (int);
How to interpret this and what's the use of declaring in this weird way?
In signal.h there is declaration of signal function:
void (*signal(int signo, void (*func)(int))) (int);
How to interpret this and what's the use of declaring in this weird way?
The signal function takes an int and a function pointer as arguments, and returns a function pointer. The function pointer argument and the returned function pointer each take an int argument, and returns void.
The signal prototype is sometimes written this way:
typedef void (*signal_handler_type) (int);
signal_handler_type signal (int, signal_handler_type);
Since the signal function allows the caller to replace the existing signal handler, it returns the one that was replaced after the call.
on APUE,
The prototype for the signal function states that the function requires two arguments and returns a pointer to a function that returns nothing (void ). The signal function's first argument, signo , is an integer. The second argument is a pointer to a function that takes a single integer argument and returns nothing. The function whose address is returned as the value of signal takes a single integer argument (the final (int) ). In plain English, this declaration says that the signal handler is passed a single integer argument (the signal number) and that it returns nothing. When we call signal to establish the signal handler, the second argument is a pointer to the function. The return value from signal is the pointer to the previous signal handler.
The perplexing signal function prototype shown can be made much simpler through the use of the following typedef:
typedef void Sigfunc(int);
Then the prototype becomes
Sigfunc *signal(int, Sigfunc *)
Signal function specifies a way to handle the signals with the signal number specified by signo(here).
Parameter func specifies one of the three ways in which a signal can be handled by a program:
you can look
[here][1]
[1]: http://www.cplusplus.com/reference/csignal/signal/ for more details