Connecting Tech Pros Worldwide Forums | Help | Site Map

Wrapping functions with variable argument list

Newbie
 
Join Date: Jun 2007
Posts: 1
#1: Jun 20 '07
Hi All,
As part of my job, I need to wrap around an existing library of functions.
Some functions have the prototype
void foo(int keyword, ...)
{
}
where ... could be a list of any size, of mixed parameter type, terminated by int 0
e.g.
foo(1 /*keyword*/, "Hello", 3.4, "World", 0 /*list terminator*/);

I need to create a wrapper
void bar(int keyword, ...) //must have same signature as foo
{
//some processing
foo(keyword, ...); // how do I pass va_args list without actually using va_args

}

Using va_args semantics is not an option because foo is already deployed in other applications and its prototype cannot change.
How do I accomplish this?
I understand that I probably need to use assembly to play with the stack arguments, but I don't know how.

Thanks

Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,370
#2: Jun 20 '07

re: Wrapping functions with variable argument list


Quote:

Originally Posted by ptugarin

I need to create a wrapper
void bar(int keyword, ...) //must have same signature as foo
{
//some processing
foo(keyword, ...); // how do I pass va_args list without actually using va_args

}

I believe your wrapper has to use va_args to get the arguments used on the bar to call foo(keyword, ...). That may require that you limit the number of arguments.
Reply