#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    3
    Rep Power
    0

    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
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    3
    Rep Power
    0
    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.

IMN logo majestic logo threadwatch logo seochat tools logo