J
John Guo
Hi all,
I am trying to nest two functions both with variable length arguments.
(The only reason I nested them is that I called the outer function in
too many places, I don't want to replace every calls with the new one).
void outerFunction(const int arg1, const int arg2, ...)
{
int arg3;
va_list ap;
va_start(ap, arg2);
innerFunction(arg3, ap);
va_end(ap);
}
void innerFunction(int arg, ...)
{
va_list ap;
va_start(ap, arg);
char a[255];
strcpy(a, va_arg(ap,char*));
int x = va_arg(ap,int);
cout<<a<<endl;
cout<<x<<endl;
va_end(ap);
}
Say if I call outerfunction with
outFunction(1,2, "ProcessName", 5)
As I debug this, it seems that ap before passed in is ok to read using
va_arg(), but in innerfunction, it doesn't work, read out some garbage
in a and x.
Could someone give some comments on this? Any help is greatly
appreciated.
John
I am trying to nest two functions both with variable length arguments.
(The only reason I nested them is that I called the outer function in
too many places, I don't want to replace every calls with the new one).
void outerFunction(const int arg1, const int arg2, ...)
{
int arg3;
va_list ap;
va_start(ap, arg2);
innerFunction(arg3, ap);
va_end(ap);
}
void innerFunction(int arg, ...)
{
va_list ap;
va_start(ap, arg);
char a[255];
strcpy(a, va_arg(ap,char*));
int x = va_arg(ap,int);
cout<<a<<endl;
cout<<x<<endl;
va_end(ap);
}
Say if I call outerfunction with
outFunction(1,2, "ProcessName", 5)
As I debug this, it seems that ap before passed in is ok to read using
va_arg(), but in innerfunction, it doesn't work, read out some garbage
in a and x.
Could someone give some comments on this? Any help is greatly
appreciated.
John