Some complex function prototypes like signal()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lovecreatesbeauty

    #1

    Some complex function prototypes like signal()

    Hello,

    I'm confused by some complex function prototypes. Would you please
    explain those to me in detail with C language syntax itself with your
    rich knowledge & experiences. Thank you.


    1. The prototype of function signal in signal.h:

    void (*signal(int sig, void (*func)(int)))( int);

    it's some complex to me. Please explain the C language syntax used to
    make up this complex prototype.



    2. And I saw another function prototype:

    void interrupt (*oldhandler)() ;

    -Is it legal?

    -If it's a right prototype, what does identifier "interrupt" mean?
    Should it be a type qualifier?



    Thanks

    ---
    lovecreatesbeau ty

  • alexmdac@hotmail.com

    #2
    Re: Some complex function prototypes like signal()


    lovecreatesbeau ty wrote:
    [color=blue]
    > I'm confused by some complex function prototypes.[/color]

    "The C Programming Language" has a good section on this subject. They
    provide source for a program that translates these type definitions
    into english.
    [color=blue]
    > void (*signal(int sig, void (*func)(int)))( int);[/color]

    You can simplify this:

    /* Pointer to a function that takes an int and returns nothing. */
    typedef void (*SIGNAL_HANDLE R)(int);

    /* Simplified signal prototype. */
    SIGNAL_HANDLER signal( int signal, SIGNAL_HANDLER handler );
    [color=blue]
    > void interrupt (*oldhandler)() ;[/color]
    This is a pointer to a function which returns nothing.

    Comment

    • Jonathan Bartlett

      #3
      Re: Some complex function prototypes like signal()

      al.h:[color=blue]
      >
      > void (*signal(int sig, void (*func)(int)))( int);
      >
      > it's some complex to me. Please explain the C language syntax used to
      > make up this complex prototype.
      >[/color]

      The return type for signal is a function pointer that, when called takes
      one int argument.

      func is a function pointer that takes one int argument.

      For more about function pointers, see http://www.newty.de/fpt/index.html

      Jon
      ----
      Learn to program using Linux assembly language

      Comment

      Working...