Wrap a variable parameter function in C ++

I would like to wrap the xmlrpc "call" function (which takes a variable number of parameters) with another function (also taking a variable number of parameters). I would just like to pass a variable number of parameters that are passed into my wrapper function to the xmlrpc call function. I know how to use va_start and va_arg, but I really don't need the values ​​that are passed, I just want to forward them along with the wrapped function. Is it possible?

specification for the function that I would like to wrap,

call(const char* url, const char* function, const char* paramSpec, void* result, ...);

my wrapper will take care of the first three parameters and the resulting result, it just needs to redirect its additional parameters to the call function

+3
source share
3 answers

Unfortunately, there is no way to provide a perfect transfer of a function that takes a variable number of arguments using syntax .... This is why it is best to implement all the functions of a list of variable variable variables in terms of host functions va_listand provide both interfaces to any client code. That's why in the standard library there printfand vprintf, sprintfand vsprintfetc.

vcall , va_list, , . , , , , call . .

+5

, , "..." va_list. vprintf.

, (...) (...)

+2

This may be possible with evil hacks on some platforms. On x86, the arguments are pushed onto the stack from right to left, so if you need to remove the return address from the stack, click the extra arguments, then replace it, you can (theoretically) do what you want. The hard part is when you want to do something with the return value from the shell ...

0
source

Source: https://habr.com/ru/post/1713482/


All Articles