appending last argument to (wrap(ed)) variadic function call

Florian Weimer fweimer@redhat.com
Mon Feb 24 11:20:00 GMT 2020


* Alexandre François Garreau:

> I want to wrap a call to a variadic function (which have both a really 
> variadic version, and one taking a va_list as argument), and let its last 
> argument be fixed by this wrapper (accordingly modifying the fixed argument 
> that specify about the variable arguments and their types)… how can I do 
> that?

You cannot access the last argument unless you know the types of all the
preceding arguments.  A GCC extension, __builtin_va_arg_pack_len, allows
you to get the number of arguments, but if they have unknown types, that
does not really help to solve this problem.

However, you can implement something like this in a fairly
straightforward way in C++11.

Thanks,
Florian



More information about the Libc-help mailing list