More questions about casting function pointers ..

Discussion in 'C Programming' started by Alfonso Morra, Aug 31, 2005.

  1. Hi,

    I have two func ptr prototypes declared as :

    typedef void (*VFP)(void) ;
    typedef int(MyCallback*)(enum_1, enum2, int, void*) ;

    I hav a struct as ff:

    typedef struct {
    VFP mini_callback ;
    VFP data_callback ;
    ...
    }FunctorStruct ;

    I can assign a function ptr of type MyCallback to mini_callback or
    data_callback (after suitable casts to VFP).

    Assuming i have function foo defined as ff:

    int foo( FunctorStruct *fctor ) {
    /* code here to call function pointed to by data_callback
    assuming we know the function pointed to is of type
    MyCallback */

    (MyCallback)fctor->data_callback( ONE, TWO, 100, NULL ) ; /* <- dosen't
    compile !*/
    }


    The compiler dosen't grok this. When I try to compile the above snippet,
    it (the compiler) barfs and issues the ff message: "'VFP' : too many
    arguments for call through pointer-to-function".

    How do I call the function - cast to its correct type?

    tkx
     
    Alfonso Morra, Aug 31, 2005
    #1
    1. Advertising

  2. Alfonso Morra wrote:
    >
    > typedef void (*VFP)(void) ;
    > typedef int(MyCallback*)(enum_1, enum2, int, void*) ;
    >
    > I hav a struct as ff:
    >
    > typedef struct {
    > VFP mini_callback ;
    > VFP data_callback ;
    > ...
    > }FunctorStruct ;
    >
    > I can assign a function ptr of type MyCallback to mini_callback or
    > data_callback (after suitable casts to VFP).
    >
    > Assuming i have function foo defined as ff:
    >
    > int foo( FunctorStruct *fctor ) {
    > /* code here to call function pointed to by data_callback
    > assuming we know the function pointed to is of type
    > MyCallback */
    >
    > (MyCallback)fctor->data_callback( ONE, TWO, 100, NULL ) ; /* <- dosen't
    > compile !*/


    ((MyCallback) fctor->data_callback)( ONE, TWO, 100, NULL ) ;

    > }


    --
    Peter
     
    Peter Nilsson, Aug 31, 2005
    #2
    1. Advertising

  3. On Wed, 31 Aug 2005 00:47:06 +0000 (UTC), Alfonso Morra
    <> wrote:

    >Hi,
    >
    >I have two func ptr prototypes declared as :
    >
    >typedef void (*VFP)(void) ;
    >typedef int(MyCallback*)(enum_1, enum2, int, void*) ;


    I hope you meant (*MyCallback).




    <<Remove the del for email>>
     
    Barry Schwarz, Aug 31, 2005
    #3
  4. Barry Schwarz wrote:

    > On Wed, 31 Aug 2005 00:47:06 +0000 (UTC), Alfonso Morra
    > <> wrote:
    >
    >
    >>Hi,
    >>
    >>I have two func ptr prototypes declared as :
    >>
    >>typedef void (*VFP)(void) ;
    >>typedef int(MyCallback*)(enum_1, enum2, int, void*) ;

    >
    >
    > I hope you meant (*MyCallback).
    >
    >

    Yup. Typo. sorry about that should be :

    typedef int (*MyCallback)(enum_1, enum2, int, void*) ;

    >
    >
    > <<Remove the del for email>>
     
    Alfonso Morra, Aug 31, 2005
    #4
    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. Dirk Vanhaute
    Replies:
    10
    Views:
    2,858
    Dirk Vanhaute
    Oct 22, 2004
  2. Alfonso Morra

    casting function pointers ?

    Alfonso Morra, Jul 27, 2005, in forum: C Programming
    Replies:
    4
    Views:
    566
    Barry Schwarz
    Jul 30, 2005
  3. Alfonso Morra

    Baffled by this ... (casting of function pointers)

    Alfonso Morra, Aug 26, 2005, in forum: C Programming
    Replies:
    7
    Views:
    367
    Denis Kasak
    Aug 26, 2005
  4. Chad

    More on pointers to pointers.

    Chad, Mar 31, 2006, in forum: C Programming
    Replies:
    6
    Views:
    286
    Dave Vandervies
    Apr 1, 2006
  5. cerr

    pointers, pointers, pointers...

    cerr, Apr 7, 2011, in forum: C Programming
    Replies:
    12
    Views:
    680
Loading...

Share This Page