question about function pointer

Discussion in 'C Programming' started by key9, Sep 16, 2006.

  1. key9

    key9 Guest

    Hi all

    passing argument of "lib_init_terminal" from incompatible pointer type

    invoke code slice
    =================
    lib_init_terminal (&sys_init_signals);


    prototype
    =========
    void sys_init_signals (void);


    int lib_init_terminal (void *ptr_sys_init_signals(void))
    {
    (*ptr_sys_init_signals)();
    }



    where 's the mistake?




    thank you very much

    your key9
    key9, Sep 16, 2006
    #1
    1. Advertising

  2. key9 wrote:
    > Hi all
    >
    > passing argument of "lib_init_terminal" from incompatible pointer type
    >
    > invoke code slice
    > =================
    > lib_init_terminal (&sys_init_signals);
    >
    >
    > prototype
    > =========
    > void sys_init_signals (void);
    >
    >
    > int lib_init_terminal (void *ptr_sys_init_signals(void))
    > {
    > (*ptr_sys_init_signals)();
    > }
    >
    >
    >
    > where 's the mistake?


    Why is it so hard for people to post compilable code? Surrounding your
    call with 'int main(void) {' and '}' would have been easier for you that
    those stupid tags with equal-sign underlining.

    The answer:

    void sys_init_signals(void);

    #if 0
    /* your illegal form, which claims ptr_sys_init_signals returns
    a pointer-to-void */
    int lib_init_terminal(void *ptr_sys_init_signals(void))

    /* a form that works */
    int lib_init_terminal(void (*ptr_sys_init_signals) (void))
    #endif
    /* and a cleaner form that works */
    int lib_init_terminal(void ptr_sys_init_signals(void))
    {
    (*ptr_sys_init_signals) ();
    return 0; /* added. You claim lib_init_terminal
    returns an int, but you don't return
    one. */
    }

    int main(void)
    {
    lib_init_terminal(&sys_init_signals);
    return 0;
    }
    Martin Ambuhl, Sep 16, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. glen stark
    Replies:
    2
    Views:
    702
    Ron Natalie
    Oct 10, 2003
  2. Fraser Ross
    Replies:
    4
    Views:
    1,043
    Fraser Ross
    Aug 14, 2004
  3. Replies:
    10
    Views:
    697
    Chris Torek
    Feb 4, 2005
  4. murgan
    Replies:
    6
    Views:
    4,861
    Thad Smith
    Dec 21, 2005
  5. Vijai Kalyan
    Replies:
    4
    Views:
    704
    Vijai Kalyan
    Nov 8, 2005
Loading...

Share This Page