I have two variadic function as foo(format, ...)
and bar(format, ...)
. I want to implement function foo
so that it can invoke bar
with the same list of arguments it has. That is,
foo(format...)
{
...
bar(format, ...);
}
For instance, invoking foo("(ii)", 1, 2)
will invoke bar
with same arguments bar("(ii)", 1, 2)
. How should this foo
function be implemented?
PS: function bar
is from a legacy library which I cant change its interface.
Can't be done, as long as all you have is a bunch if functions with ...
arguments.
You have to plan ahead for things like that and implement each variadic fuinction in two-staged fashion
void vfoo(format, va_list *args) {
/* Process `*args` */
}
void foo(format, ...) {
va_list args;
va_start(args, format);
vfoo(format, &args);
va_end(args);
}
Once you have each of your variadic functions implemented through a pair of va_list *
function and ...
function, you can delegate the calls using the va_list *
versions of the functions
void vfoo(format, va_list *args) {
...
vbar(format, args);
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With