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. Advertising

  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. Advertising

  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. 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. Replies:
    0
    Views:
    559
  2. Kevin Spencer

    Re: Simple Simple question!!!

    Kevin Spencer, Jun 25, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    666
    Kevin Spencer
    Jun 25, 2004
  3. Daniel Frey

    Simple Question - Simple Answer?

    Daniel Frey, Dec 28, 2004, in forum: XML
    Replies:
    4
    Views:
    844
    Daniel Frey
    Jan 12, 2005
  4. Oli

    simple simple question

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

    simple, simple array question

    Peter Bailey, Apr 8, 2008, in forum: Ruby
    Replies:
    7
    Views:
    215
    Peter Bailey
    Apr 8, 2008
Loading...

Share This Page