Variadic functions use a calling convention in which the caller is responsible for expressing function parameters from the stack, so yes, this can be done dynamically. It is not standardized in C and usually requires some assembly in order to manually press the necessary parameters and correctly use the variational function.
The cdecl calling cdecl requires the arguments to be inserted in the correct order, and after the call, the bytes passed as arguments before the call are returned. Thus, the called function can take an arbitrary number of parameters, since the calling party will process the return of the stack pointer to the state before the call. The space occupied by the arguments before ... is a safe lower bound for the number of bytes skipped. Additional variable arguments are interpreted at run time.
FFCALL is a library that provides wrappers for the dynamic transition of parameters to variational functions. A group of avcall features that interest you. Here is an example of calling the functions you specified above:
#include <avcall.h> av_alist argList; int retVal; av_start_int(argList, some_function, retval); av_int(argList, a); av_int(argList, b); av_type(argList, val1); ... av_type(argList, valn); av_call(argList);
You can also find this link by discussing the creation of wrappers around variational functions in C to interest in justifying why this is not part of the C standard.
source share