void *

Discussion in 'C++' started by Michael Sgier, Sep 8, 2009.

  1. Hi
    how should I call that function? I don't understant the parameter. What
    exactly is void * inRefcon doing?
    Many thanks
    Michael

    --------
    int GetFDCallback(void * inRefcon)
    {
    return FD;
    }
     
    Michael Sgier, Sep 8, 2009
    #1
    1. Advertising

  2. thanks Paavo
    so how can i dereference that? the code below does not work:
    Many thanks again
    Michael


    if ( GetFDCallback == (int*)1 ) {
    sometheing;
    }
     
    Michael Sgier, Sep 8, 2009
    #2
    1. Advertising

  3. Michael Sgier

    Default User Guest

    Michael Sgier wrote:

    > thanks Paavo
    > so how can i dereference that? the code below does not work:
    > Many thanks again
    > Michael
    >
    >
    > if ( GetFDCallback == (int*)1 ) {
    > sometheing;
    > }


    1. Please include quotes to provide for your posts. See almost every
    other message in the group.

    2. What do you mean by, "doesn't work"?

    3. Also, you didn't deference anything in the snippet.



    Brian

    --
    Day 217 of the "no grouchy usenet posts" project
     
    Default User, Sep 8, 2009
    #3
  4. Michael Sgier

    mikethebike Guest

    Hi Brian

    ----------
    > >     if ( GetFDCallback == (int*)1 ) {
    > >             sometheing;
    > >     }

    ---------

    dereferencing? might be the wrong word? Anyway GetFDCallback returns
    FD. FD is defined as int. Actually I want to:
    if FD == 1 do that
    elseif FD == 2 do other
    etc.
    Could I simmply leave away: (void * inRefcon)? I don't see the point
    why this has been done so.
    Thanks
    Michael
     
    mikethebike, Sep 9, 2009
    #4
  5. Michael Sgier

    mikethebike Guest

    That's the error I get with the above:
    ------
    comparison between distinct pointer types ‘int (*)(void*)’ and ‘int*’
    lacks a cast
    ----
    how should I do that cast?
    Thanks
     
    mikethebike, Sep 9, 2009
    #5
  6. Michael Sgier

    Ismo Salonen Guest

    mikethebike wrote:
    > Hi Brian
    >
    > ----------
    >>> if ( GetFDCallback == (int*)1 ) {
    >>> sometheing;
    >>> }

    > ---------
    >
    > dereferencing? might be the wrong word? Anyway GetFDCallback returns
    > FD. FD is defined as int. Actually I want to:
    > if FD == 1 do that
    > elseif FD == 2 do other
    > etc.
    > Could I simmply leave away: (void * inRefcon)? I don't see the point
    > why this has been done so.
    > Thanks
    > Michael


    The error message suggests that you are not calling the function (thus
    just comparing the address).

    if ( GetFDCallback() == (int*)1 ) {

    Add the () there.

    ismo
     
    Ismo Salonen, Sep 9, 2009
    #6
  7. * Ismo Salonen:
    > mikethebike wrote:
    >> Hi Brian
    >>
    >> ----------
    >>>> if ( GetFDCallback == (int*)1 ) {
    >>>> sometheing;
    >>>> }

    >> ---------
    >>
    >> dereferencing? might be the wrong word? Anyway GetFDCallback returns
    >> FD. FD is defined as int. Actually I want to:
    >> if FD == 1 do that
    >> elseif FD == 2 do other
    >> etc.
    >> Could I simmply leave away: (void * inRefcon)? I don't see the point
    >> why this has been done so.
    >> Thanks
    >> Michael

    >
    > The error message suggests that you are not calling the function (thus
    > just comparing the address).
    >
    > if ( GetFDCallback() == (int*)1 ) {
    >
    > Add the () there.


    According to Michael's original post the function signature is

    int GetFDCallback( void* )

    so the above would be very invalid code.

    I think any advice here about how to "call" the function would probably mislead
    Michael, since it seems that his idea of "calling" it is just a wild idea.

    Mostly the problem boils down to Michael assuming that readers of his post are
    telepathic. Well, Michael, we're not telephathic: offhand we have no clue as to
    where you stumbled over this function or what it's about or whether its name is
    indicative of something or just a name you cooked up, or whatever, and no-one is
    going to spend time trying to find out. As suggested else-thread, RTFM.


    Cheers & hth.,

    - Alf
     
    Alf P. Steinbach, Sep 9, 2009
    #7
  8. Michael Sgier

    Default User Guest

    mikethebike wrote:

    > Hi Brian
    >
    > ----------
    > > >     if ( GetFDCallback == (int*)1 ) {
    > > >             sometheing;
    > > >     }

    > ---------
    >
    > dereferencing? might be the wrong word? Anyway GetFDCallback returns
    > FD. FD is defined as int. Actually I want to:
    > if FD == 1 do that
    > elseif FD == 2 do other
    > etc.
    > Could I simmply leave away: (void * inRefcon)? I don't see the point
    > why this has been done so.


    I can't figure out what you want. Start over and lay out the
    requirements for what you are trying to do, including a small usage
    example. Don't bother with the code, as that's not what you need anyway.



    Brian

    --
    Day 219 of the "no grouchy usenet posts" project
     
    Default User, Sep 9, 2009
    #8
    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. Sergio

    returning a void (*)(void)

    Sergio, Jan 5, 2005, in forum: C++
    Replies:
    6
    Views:
    439
    Jonathan Turkanis
    Jan 5, 2005
  2. Ollej Reemt
    Replies:
    7
    Views:
    552
    Jack Klein
    Apr 22, 2005
  3. Stig Brautaset

    `void **' revisited: void *pop(void **root)

    Stig Brautaset, Oct 25, 2003, in forum: C Programming
    Replies:
    15
    Views:
    795
    The Real OS/2 Guy
    Oct 28, 2003
  4. Replies:
    5
    Views:
    843
    S.Tobias
    Jul 22, 2005
  5. Replies:
    1
    Views:
    413
    Victor Bazarov
    May 23, 2007
Loading...

Share This Page