More questions about casting function pointers ..

A

Alfonso Morra

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
 
P

Peter Nilsson

Alfonso said:
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 ) ;
 
B

Barry Schwarz

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top