473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

More questions about casting function pointers ..

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

Nov 15 '05 #1
3 1515
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

Nov 15 '05 #2
On Wed, 31 Aug 2005 00:47:06 +0000 (UTC), Alfonso Morra
<sw***********@the-ring.com> 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>>
Nov 15 '05 #3


Barry Schwarz wrote:
On Wed, 31 Aug 2005 00:47:06 +0000 (UTC), Alfonso Morra
<sw***********@the-ring.com> 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>>


Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: He Shiming | last post by:
Hi, I'm having a little bit of trouble regarding pointer casting in my program. I don't understand why the following two cases produce different results. Case 1: IInterface *pInterface = new...
15
by: Marc Thrun | last post by:
Hello, I've got a few questions: 1) Given the two structs struct A { int x; }; and
4
by: AzizMandar | last post by:
C++ Event Coding Questions I have done some simple programs in C++ and read a lot of good C++ books (Including The C++ Programing Language, and C++ Primer) I am trying to understand and...
9
by: Jess | last post by:
Hello, It seems both static_cast and dynamic_cast can cast a base class pointer/reference to a derived class pointer/reference. If so, is there any difference between them? In addition, if I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.