Let's consider 2 functions, void fooA(int argc, ...)
and void fooB(int argc, ...)
I need to pass the variable arguments I get from fooA to fooB. And except for passing them to fooB, I never need to handle these variable arguments in fooA.
I tried something like changing fooB to void fooB(int argc, void* argv)
and pass the arguments like in the following code:
void fooA(int argc, ...) {
// Some processing ...
va_list list;
va_start(list, argc);
void **argv = NULL;
argv = malloc(argc * sizeof(void*));
for (int i = 0; i < argc; i++)
argv[i] = va_arg(list, void*);
fooB(argc, argv);
}
But it's not very clean, and I would like to know if there is a way to do that without even handling the variable arguments in the fooA function.
EDIT: It's not a dupe of this question because in my case I can modify fooA or fooB definition (even if I would not like to). And even if it works great, I can't accept Jonathan Leffler technical because I just can't put a forwarder for each fooB-like function. They are called with a static function pointer array and I need to have all my fooB methods alone in the same C file.