473,695 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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)fct or->data_callbac k( 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 1527
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)fct or->data_callbac k( 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)(e num_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
2433
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 CImplementation(); pInterface->Method(); Case 2:
15
1981
by: Marc Thrun | last post by:
Hello, I've got a few questions: 1) Given the two structs struct A { int x; }; and
4
6695
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 implement an Event based program and Message system. I have a very basic event engine that I'm feeling works a bit backwards. I'm looking for documents, source code, and books that may help me better understand how to implement this type of code. I am...
9
2455
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 have a derived class object and then upcast it to its base class, which cast operator should I use? Is it static_cast, or, can I simply cast it implicitly without any operator? Does this upcasting remove the derived class portion of the object?...
0
8640
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9001
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7670
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5841
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4348
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4587
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1980
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.