September 6th, 2013, 01:40 AM
Function pointer (signal) - help required in understanding
I am reading Linux programming interface. Now I am stuck with understanding the definition of signal function. Book says
with my understanding on function pointer, I am not able to understand how this function works...
"void ( *signal(int sig, void (*handler)(int)) ) (int);
Returns previous signal disposition on success, or SIG_ERR on error"
oldHandler = signal(SIGINT, newHandler);
Assuming, i remove the part of "(int sig, void (*handler)(int), my function will look like
which is a function pointer using one int argument and returns none. But what would function definition like this would mean
How it returns something?
Last edited by nu2c; September 6th, 2013 at 02:16 AM.
Reason: changed the heading
September 6th, 2013, 02:38 AM
I couldn't find any explanation for the query I raised before anywhere on the internet. Finally I looked in man pages and found that signal is defined as
This makes clear that singal function takes 2 arguments, and returns to a pointer a function which takes one argument and returns void.
typedef void (*sighandler_t)(int);
sighandler_t signal(int signum, sighandler_t handler);