Tell me how to implement the function:
int test(...){ printf(...);} That is, pass the va_list parameters to the next function.
Tell me how to implement the function:
int test(...){ printf(...);} That is, pass the va_list parameters to the next function.
It's just impossible to pass an undefined list of arguments, there is no syntax for this in the language. However, the problem can be circumvented, as indicated here : the function to which you transfer control must have an option that accepts va_list .
For your case, you can use vprintf :
void test(char *format, ...) // должен быть хотя бы один аргумент { va_list args; va_start(args, format); vprintf(format, args); va_end(args); } Or macro:
#define prn(A,...) printf(A,__VA_ARGS__) sometimes it's easier, especially if you need to add additional arguments to VA_ARGS. But for the mind, you still need to learn about the VA_ * interface .
Source: https://ru.stackoverflow.com/questions/837535/
All Articles