Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > More questions about casting function pointers ..

Reply
Thread Tools

More questions about casting function pointers ..

 
 
Alfonso Morra
Guest
Posts: n/a
 
      08-31-2005
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

 
Reply With Quote
 
 
 
 
Peter Nilsson
Guest
Posts: n/a
 
      08-31-2005
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

 
Reply With Quote
 
 
 
 
Barry Schwarz
Guest
Posts: n/a
 
      08-31-2005
On Wed, 31 Aug 2005 00:47:06 +0000 (UTC), Alfonso Morra
<(E-Mail Removed)> 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>>
 
Reply With Quote
 
Alfonso Morra
Guest
Posts: n/a
 
      08-31-2005


Barry Schwarz wrote:

> On Wed, 31 Aug 2005 00:47:06 +0000 (UTC), Alfonso Morra
> <(E-Mail Removed)> 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>>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
Casting function pointers Nudge C Programming 7 11-17-2005 10:50 PM
Baffled by this ... (casting of function pointers) Alfonso Morra C Programming 7 08-26-2005 02:35 PM
casting function pointers ? Alfonso Morra C Programming 4 07-30-2005 12:46 AM
Casting Function pointers : Can anyone correct this MS Knowledge base Example pls ? Dirk Vanhaute C++ 10 10-22-2004 08:25 AM



Advertisments