Thread: header signal.h

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    18

    header signal.h

    hi all... just a clarification...

    this is a function defined in the csignal library to handle (return(ed)?! - os?!) signals:
    void (*signal(int sig, void (*func)(int)) ) (int);

    i interpret it as:

    a pointer to a void function that takes two arguments - a signal and a pointer to a function that itself needs an int arg. so far so good.

    what does the (int) at the very and do/set?!

    thanks....

  2. #2
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    In fact, it means that the function "signal" return a function pointer, and this function return nothing (void) and takes one argument of type "int".

    The syntax is a bit hard to read. This is an equivalent syntax:

    Code:
    typedef void (*sighandler_t)(int);
    
    sighandler_t signal(int signum, sighandler_t handler);
    I hate real numbers.

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    18
    thanks...

    pardon my ignorance but... why would you want to make a type out of a void function pointer?!

  4. #4
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    pardon my ignorance but... why would you want to make a type out of a void function pointer?!
    Careful, here, "sighandler_t" is a synonym for "void (*)(int)". Why would we want to do such ? Well, it makes the syntax more concise.

    Is it clearer ?
    I hate real numbers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM