-
Passing ... as a param?
I'm trying to abstract out this logging API I'm using. The prototype for the logging function is
Code:
log(int level, char * fmt, ...)
So I wanted to make my own function
Code:
mylog(int level, char * fmt, ...)
That calls theirs. Is there some way I can pass the ... arg from my function into the actual logging function?
-
You can't do that. At most, you can create a va_list out of the ellipsis and pass it to some function similar to `log' that takes a va_list in place of variable arguments. Or if your compiler supports variadic macros, then you can use one instead of a function call.
-
All the standard variadic functions eg.
printf( const char *fmt, ... );
also have an equivalent varargs function
vprintf( const char *fmt, va_list ap );
Writing myprintf() would use the va_start/va_end macros, and call the vprintf() function at some point.
Unless you have a vlog(int level, va_list ap), you're pretty much stuck without resorting to extreme trickery.
-
Can't you use C99 variadic argument macro?
Code:
#define mylog(a,...) do { mylogfunc(a,__VA_ARGS__); \
log(a,__VA_ARGS__); } while(0)