Possible Duplicate:
C Programming: Forward variable argument list.
What I’d like to do is send data to a logging library (that I can’t modfify) in a printf kind of way.
So I’d like a function something like this:
void log_DEBUG(const char* fmt, ...) {
char buff[SOME_PROPER_LENGTH];
sprintf(buff, fmt, <varargs>);
log(DEBUG, buff);
}
Can I pass varargs to another vararg function in some manner?
You can’t forward the variable argument list, since there’s no way to express what’s underneath the
...as a parameter(s) to another function.However you can build a
va_listfrom the...parameters and send that to a function which will format it up properly. This is whatvsprintfis for. Example: