c - How do I pass "..." (variable-length arg list), unchanged, through my function to another? -
this question has answer here:
old client code:
printf("foo: %d, bar: %s.\n", f, b);
what i'd replace printf (& 100's others it) with:
my_printf(ctrl1, ctrl2, "foo: %d, bar: %s.\n", f, b);
implementation of my_printf
void my_printf(ctrlt1 c1, ctrl c2, char* fmt, ...) { /* stuff c1 & c2 */ fprintf(log, fmt, **what_goes_here**); }
what i've tried far
it seems there ought simple, direct way pass list of arguments associated ...
through fprintf. tried fprintf(log, fmt, ...);
compiler complains, "syntax error before '...' token".
i tried: va_list ap;
va_start(ap, fmt);
fprintf(log, fmt, ap);
the call va_list compiles , runs without coring, what's being passed printf plainly not same thing passed function ...
, may judged output (representation of non-printing char).
if push comes shove, walk through contents of va_list brute-force seems stupid. there no simple token or syntax pass ...
through?
this isn't general solution, stdio functions, @ ones start letter v
, such vfprintf
. take va_list
last parameter, instead of ...
.
void my_printf(ctrlt1 c1, ctrl c2, char* fmt, ...) { /* stuff c1 & c2 */ va_list ap; va_start (ap, fmt); vfprintf (log, fmt, ap); va_end (ap); }
Comments
Post a Comment