Is there any problem with sending function pointers through in a
variable argument list? I have a function like the following:
typedef (*ptr2FuncType1 )( int );
typedef (*ptr2FuncType2 )( double );
void SomeClass::DoSo mething( unsigned int num_something, unsigned long
num_something_e lse, ptr2FuncType1 handler_one, ... )
The functions I am passing in are in a different cpp file, but they
are not memeber functions of any class.
Where the ... represents the function pointers which I am sending to
the function. Inside that function I initialize a member array that
contains those pointers to functions. So I use va_start( arglist,
handler_one ) to start the arg list.
Then to get to each function pointer I use
m_pFuncArray[i] = va_arg( arglist, ptr2FunctionTyp e2 );
etc....
When I try and call the functions later in another class function, I
get a program crash from memory error. The thing I am thinking is that
the program needs to code segment as well as the address of the
function to be able to call it. Is there anything special I need to do
with variable arguments to get functions pointers to work correctly?
Thanks!
Alex Earl 1 6738
"Alex" <sl*********@ho tmail.com> wrote in message news:b7******** *************** ***@posting.goo gle.com... Then to get to each function pointer I use m_pFuncArray[i] = va_arg( arglist, ptr2FunctionTyp e2 );
Provided that the argument is really of type ptr2FunctionTyp e2, this should be ok.
Are you sure you haven't screwed up the types. There is NO checking provided
by va_arg. Also make sure you have extracted the prior args in the list correctly
as once you screw one up the ohters can be hosed.
When I try and call the functions later in another class function, I get a program crash from memory error. The thing I am thinking is that the program needs to code segment as well as the address of the function to be able to call it. Is there anything special I need to do with variable arguments to get functions pointers to work correctly?
The compier is supposed to take all that into account when encoding the
pointer. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kapt. Boogschutter |
last post by:
I'm trying to create a function that has at least 1 Argument but can also
contain any number of Arguments (except 0 because my function would have no
meaning for 0 argument).
The arguments passed to the function are strings or must be (automaticly
converted to a string e.g. the number 10 should become the string "10".
My problem is that I can only find samples and description of printf() like
functions where the optional arguments and...
|
by: S?ren Gammelmark |
last post by:
Hi
I have been searching the web and comp.lang.c of a method of using
variable-argument function pointers and the like. And some of the
questions arising in this post are answered partly in these posts, but
I ask mainly for a way to found a way to solve this problem. I'm a
hobbyist so there might be an alltogether better solution to the
problem, so please come with any solution you might think of. I'm open
to ideas. --- And i'm not...
|
by: baumann |
last post by:
hi all,
typedef int (*pfunc)(int , int);
pfunc a_func;
i know it's ok,
but how can define a_func without typedef statement?
thanks .
|
by: Russ Chinoy |
last post by:
Hi,
This may be a totally newbie question, but I'm stumped.
If I have a function such as:
function DoSomething(strVarName) {
.....
}
|
by: sphinx.moro |
last post by:
Hello,
I have a function which is coded to receive an unknown number of
arguments
void Process(int i_ss, int Nerr, ...) {
va_list pa; /* variable argument list*/
va_start(pa, Nerr);
sprintf(FMT, "SS=%d, Er=%d ", i_ss, Nerr);
strcat(FMT, "A1=<%s>, A2=<%s> ");
vsprintf(line, FMT, pa);
va_end(pa);
| |
by: prasanthag |
last post by:
Hi,
I am a newbie to this group. I have a problem in handling the variable
arguments passed to a function. My requirement is like this.
I have 2 functions say,
void funcX(int i, int j);
void funcY(int i, int j,char *name);
|
by: carvalho.miguel |
last post by:
hello,
imagine you have a static class method that receives a function
pointer, an int with the number of arguments and a variable number of
arguments.
in that static method you want to call that function (using its
pointer) and call it with the same argument list that was passed into
the static method.
|
by: Pedro Pinto |
last post by:
Hi there once more........
Instead of showing all the code my problem is simple.
I've tried to create this function:
char temp(char *string){
alterString(string);
return string;
|
by: Googy |
last post by:
Hi friends!!
As we know that the input parameters in a function is fixed when the
function is defined but how does printf processes variable number of
input arguments ?
For example:
1. printf("Hey! how are you"); /*No. of arguments = 1*/
2. printf("Sum of %d and %d is %d",a,b,c"); /* No. of arguments = 4*/
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |