On Mon, 12 Nov 2007 02:37:46 -0800, Boltar <bo********@yahoo.co.uk>
wrote:
>My problem is I have 2 variadic functions , one of which needs to call
the other passing its entire argument list but the other needs to be
callable from anywhere else in the program as a variadic too, ie it
*can't* have va_list as a paramater type.
eg:
void func1(char *fmt, ...)
{
prepend something to format
func2(fmt,args);
}
void func2(char *fmt,...)
{
}
How about if you provide variadic interfaces for your func1() and
func2(), and wrap the stuff that was in func2() into a new func3()
which can accept a va_list.
#include <stdio.h>
#include <stdarg.h>
void func1(char *fmt, ...)
{
/* prepend something to fmt, giving newfmt */
va_list args;
va_start (args, fmt);
func3 (newfmt, args);
va_end (args);
}
void func2(char *fmt, ...)
{
/* leave fmt unchanged */
va_list args;
va_start (args, fmt);
func3 (fmt, args);
va_end (args);
}
void func3(char *fmt, va_list arglist)
{
/* do stuff with fmt and arglist - probably like this: */
vfprintf(stderr, fmt, arglist);
}
I'm doing something similar to this - albeit in C++ - with a debug
logging class, where my equivalent of func3 is private, and I provide
a number of public interfaces which are variadic.
--
PGP key ID 0xEB7180EC