473,387 Members | 1,455 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.

variable number of arguments + function pointers

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::DoSomething( unsigned int num_something, unsigned long
num_something_else, 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, ptr2FunctionType2 );

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
Jul 19 '05 #1
1 6699

"Alex" <sl*********@hotmail.com> wrote in message news:b7**************************@posting.google.c om...

Then to get to each function pointer I use
m_pFuncArray[i] = va_arg( arglist, ptr2FunctionType2 );
Provided that the argument is really of type ptr2FunctionType2, 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.
Jul 19 '05 #2

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

Similar topics

7
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...
1
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...
42
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 .
23
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) { ..... }
1
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,...
3
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);...
3
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...
18
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;
11
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....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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...

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.