September 6th, 2013, 12:40 AM
-
Function pointer (signal) - help required in understanding
Hi All,
I am reading Linux programming interface. Now I am stuck with understanding the definition of signal function. Book says
Code:
"void ( *signal(int sig, void (*handler)(int)) ) (int);
Returns previous signal disposition on success, or SIG_ERR on error"
Usage :-
oldHandler = signal(SIGINT, newHandler);
with my understanding on function pointer, I am not able to understand how this function works...
Assuming, i remove the part of "(int sig, void (*handler)(int), my function will look like
Code:
void (*signal)(int)
which is a function pointer using one int argument and returns none. But what would function definition like this would mean
Code:
void (*signal())(int)
How it returns something?
Please help.
Last edited by nu2c; September 6th, 2013 at 01:16 AM.
Reason: changed the heading
September 6th, 2013, 01: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
Code:
typedef void (*sighandler_t)(int);
sighandler_t signal(int signum, sighandler_t handler);
This makes clear that singal function takes 2 arguments, and returns to a pointer a function which takes one argument and returns void.
thank you.