By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,395 Members | 2,505 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,395 IT Pros & Developers. It's quick & easy.

variable number of arguments + function pointers

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.