D
DSF
Hello,
While working on a couple of functions that take a variable argument
list, I discovered they were almost completely identical, except for
one line of code. What a great situation for splitting off the common
code to a common function.
Now I know that va_start must be in the function that receives the
variable number of arguments, but must va_end be there as well?
In other words: In pseudo code,
int foo1(char *str, ...)
{
va_list ap;
int ret;
va_start(ap, str);
ret = foocommon(str, ap);
va_end(ap);
return ret;
}
int foo2(char *str, ...)
{
va_list ap;
int ret;
/* code unique to foo2 goes here */
va_start(ap, str);
ret = foocommon(str, ap);
va_end(ap);
return ret;
}
int foocommon(va_list ap)
{
/* handle va_arg here */
return foocommon status value;
}
Or can va_end be placed in foocommon, allowing foo1 and foo2 to end
with return foocommon(str, ap); ?
DSF
While working on a couple of functions that take a variable argument
list, I discovered they were almost completely identical, except for
one line of code. What a great situation for splitting off the common
code to a common function.
Now I know that va_start must be in the function that receives the
variable number of arguments, but must va_end be there as well?
In other words: In pseudo code,
int foo1(char *str, ...)
{
va_list ap;
int ret;
va_start(ap, str);
ret = foocommon(str, ap);
va_end(ap);
return ret;
}
int foo2(char *str, ...)
{
va_list ap;
int ret;
/* code unique to foo2 goes here */
va_start(ap, str);
ret = foocommon(str, ap);
va_end(ap);
return ret;
}
int foocommon(va_list ap)
{
/* handle va_arg here */
return foocommon status value;
}
Or can va_end be placed in foocommon, allowing foo1 and foo2 to end
with return foocommon(str, ap); ?
DSF