Simple question

Discussion in 'C++' started by John, Apr 28, 2004.

  1. John

    John Guest

    Hi all:

    I can not understand the following line:
    typedef void (*FailureCallback)(char *,void *);

    Could someone explain it for me?

    Thanks in advance.

    John
     
    John, Apr 28, 2004
    #1
    1. Advertisements

  2. John

    Sharad Kala Guest

    "John" <> wrote in message
    news:...
    > Hi all:
    >
    > I can not understand the following line:
    > typedef void (*FailureCallback)(char *,void *);


    FailureCallback is a type of a function pointer. The function accepts char* and
    void* as parameters and it's return type is void.
    It's usage -
    typedef void (*FailureCallback)(char *,void *);
    void f( char*, void*){}

    int main(){
    FailureCallback f1;
    f1 = f;
    }

    -Sharad
     
    Sharad Kala, Apr 28, 2004
    #2
    1. Advertisements

  3. "John" <> wrote in message
    news:...
    > Hi all:
    >
    > I can not understand the following line:
    > typedef void (*FailureCallback)(char *,void *);
    >
    > Could someone explain it for me?
    >
    > Thanks in advance.
    >
    > John


    It declares a type called FailureCallback. FailureCallback is a pointer to a
    function. That function has no return value (i.e. void) and takes two
    arguments a char* and a void *.

    Pointers to functions are usually used to allow the user to customise some
    algorithm. For instance a sorting algorithm might take a pointer to a
    function to compare two of the elements to be sorted. In your case is sounds
    as if this pointer to a function is used to call some function when a
    failure occurs. You supply the function to be called and it will be called
    when a failure occurs, that's what a 'callback' is.

    john
     
    John Harrison, Apr 28, 2004
    #3
  4. John

    Tim Love Guest

    (John) writes:

    >Hi all:


    >I can not understand the following line:
    >typedef void (*FailureCallback)(char *,void *);


    >Could someone explain it for me?


    A rather old (free) Unix program called c++decl is useful in these situations,
    though it has limitations

    last/tpl: c++decl explain "void (*FailureCallback)(char *,void *)"
    declare FailureCallback as pointer to function (pointer to char, pointer to void) returning void
     
    Tim Love, Apr 28, 2004
    #4
  5. John

    John Guest

    Thank you all for your explaination.

    John

    "John Harrison" <> wrote in message news:<c6nchd$di709$-berlin.de>...
    > "John" <> wrote in message
    > news:...
    > > Hi all:
    > >
    > > I can not understand the following line:
    > > typedef void (*FailureCallback)(char *,void *);
    > >
    > > Could someone explain it for me?
    > >
    > > Thanks in advance.
    > >
    > > John

    >
    > It declares a type called FailureCallback. FailureCallback is a pointer to a
    > function. That function has no return value (i.e. void) and takes two
    > arguments a char* and a void *.
    >
    > Pointers to functions are usually used to allow the user to customise some
    > algorithm. For instance a sorting algorithm might take a pointer to a
    > function to compare two of the elements to be sorted. In your case is sounds
    > as if this pointer to a function is used to call some function when a
    > failure occurs. You supply the function to be called and it will be called
    > when a failure occurs, that's what a 'callback' is.
    >
    > john
     
    John, Apr 28, 2004
    #5
    1. Advertisements

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. Dave E
    Replies:
    7
    Views:
    926
    Josh Twist
    Jan 11, 2006
  2. Daniel Frey

    Simple Question - Simple Answer?

    Daniel Frey, Dec 28, 2004, in forum: XML
    Replies:
    4
    Views:
    1,097
    Daniel Frey
    Jan 12, 2005
  3. Replies:
    7
    Views:
    854
    Stig Brautaset
    Jul 23, 2003
  4. Eric
    Replies:
    2
    Views:
    538
    kbutterly
    Dec 7, 2006
  5. Oli

    simple simple question

    Oli, Jan 26, 2004, in forum: ASP General
    Replies:
    10
    Views:
    593
    Roland Hall
    Jan 26, 2004
  6. Peter Bailey

    simple, simple array question

    Peter Bailey, Apr 8, 2008, in forum: Ruby
    Replies:
    7
    Views:
    465
    Peter Bailey
    Apr 8, 2008
  7. Kirk

    Simple Question = simple answer?

    Kirk, Sep 23, 2003, in forum: Javascript
    Replies:
    1
    Views:
    270
    Martin Honnen
    Sep 23, 2003
  8. db
    Replies:
    7
    Views:
    418
Loading...