Hi all,
recently i came across this function (used in a logger class). I understand what it does, but i do not know how:
void Reporter::print( const char* szFormat, ...)
{
// note: m_out is a FILE*
va_list args;
va_start(args, szFormat);
vfprintf( m_out, szFormat, args);
va_end(args);
}
I read the reference, but still it's unclear to me. What is bugging me the most is that this doesn't work as expected. I get 0 for the last number and (null) for the string, although it should print some number greater than 0 and a path to a file.
Case 1:
rep.print( "Values: %08X %08X %08X %08X %08X %08X %d %s\n", val1, val2, val3, val4, val5, val6, source.GetLength(), szPath );
// source.GetLength() returns a size_t, szPath is a const char* and IS indeed a valid string
But changing it to this works fine:
Case 2:
rep.print( "Values: %08X %08X %08X %08X %08X %08X", val1, val2, val3, val4, val5, val6 );
rep.print( " %d %s\n", source.GetLength(), szPath );
Note that i'm compiling under MSVC++ 2008. The same code works fine (even the first case) under gcc. Is there a bug in the implementation of Reporter::print() or in the way I use the function? How can I make sure that it will work fine even when called as in the first case? And why does it even fail?