c++ - vprintf not consuming item from va_list -
i trying write variation of printf item beingness printed , format beingness printed adjacent parameters in phone call like...
print(2, "%s", "hello", "%.5u", 25);
i have studied on var args , came with....
void print(int count, ...) { va_list varg; va_start(varg, count); while(count-- > 0) { char* format = va_arg(varg, char*); vprintf(format, varg); } va_end(varg); }
it appears vprintf not consuming item using stack. output is
hellohello
i believe beingness expanded out too
printf("%s", "hello); printf("hello");
so doing wrong vprintf isn't consuming "hello" arg list?
update: per comment below
void print(int count, ...) { va_list varg; va_start(varg, count); while(count-- > 0) { char* format = va_arg(varg, char*); void* arg = va_arg(varg, void*); printf(format, arg); } va_end(varg); }
this seems job done.
the va_list nil address (in typical implementations). passed value function, original in calling function unmodified.
c++ c printf varargs
No comments:
Post a Comment