Say I have 2 functions
void f1(int p1, int v1, ...);
AND
void f2(int v1, ...);
Inside f1 I want to pass all parameters from variadic list to f2:
void f1(int p1, int v1, ...) {
f2(/*pass all variadic parameters*/);
}
For example when I call f1(1, 2, 3, 4, 5) I want to pass 2,3,4,5 to f2
It’s not possible directly, but you can use the
va_listtype to wrap the full complement of values and pass them to a version of the function that takes such an argument. Basically, breakf2()into:And then rework
f1()to usef2v()instead off2():This is, in theory, how
printf()andvprintf()work–printf()internally can callvprintf()so that two functionally identical implementations are not needed.(Don’t forget–you need to
#include <stdarg.h>to get access tova_list,va_start(), etc.)