S
skillzero
Is there a portable way to pass a va_list as a parameter to another
function taking a variable argument list?
I have a function that takes a printf-like format string and I'd like
to use something like %V to pass in another format string and a
va_list to allow nesting. It happens to work on my compiler, but I
wasn't sure if it's portable to use va_list's as parameters to a
variable argument function because va_list isn't always just a simple
pointer.
For example, if MyPrintF was like printf, but supported %V to take a
nested format string and va_list:
void PrintLabelF( const char *format, ... )
{
va_list args;
va_start( args, format );
MyPrintF( "Label: %V\n", format, args );
va_end( args );
}
// Print "Label: test 123\n"
PrintLabelF( "test %d", 123 );
Is it portable to do the following to get the nested va_list?
const char * nestedFormat;
va_list nestedArgs;
nestedFormat = va_arg( args, const char * );
nestedArgs = va_arg( args, va_list );
vprintf( nestedFormat, nestedArgs );
function taking a variable argument list?
I have a function that takes a printf-like format string and I'd like
to use something like %V to pass in another format string and a
va_list to allow nesting. It happens to work on my compiler, but I
wasn't sure if it's portable to use va_list's as parameters to a
variable argument function because va_list isn't always just a simple
pointer.
For example, if MyPrintF was like printf, but supported %V to take a
nested format string and va_list:
void PrintLabelF( const char *format, ... )
{
va_list args;
va_start( args, format );
MyPrintF( "Label: %V\n", format, args );
va_end( args );
}
// Print "Label: test 123\n"
PrintLabelF( "test %d", 123 );
Is it portable to do the following to get the nested va_list?
const char * nestedFormat;
va_list nestedArgs;
nestedFormat = va_arg( args, const char * );
nestedArgs = va_arg( args, va_list );
vprintf( nestedFormat, nestedArgs );