Passing Variable Args



I am trying to implement a logger. I need to pass variable number of
arguments from one func to another. Only way I could come up with was
by using va_list in the first function and pass it second function.

void Log(const char* format, ...)
{
va_list args;
va_start(args, format);
DoLog1(format, &args);
va_end;

va_list args;
va_start(args, format);
DoLog2(format, &args);
va_end;
}

void DoLog1(const char* format, va_list* args)
{
printf(format, args);
}

void DoLog2(const char* format, va_list* args)
{
// Do Something Fancy
}

This works fine but is very error prone. i.e Something like the
following will compile without any warnings and gives wrong results.

Log("Print %d", 3.00); //This prints 16 instead of 3.
Log("Print %d", (int)3.00); //This correctly prints 3.

Is there anyway I can fix this so that compiler can still emit
warnings in the above case? Thank you,

--MSR
.



Relevant Pages