Call again a variadic function (... variable number of arguments)with same arguments that its variad

M

moreau.steve

Hi guys,

I am trying to make a wrapper above a function with variable number of
arguments (called function_in_library in this example), which I cannot
modify, and for which no equivalent with va_args exist. I would like
to know if there is mean to call this function with the same arguments
of the wrapper function.
I met this issue several times and workarounded it each time making a
new function 'function_in_library2' equivalent to
'function_in_library' but with this prototype function_in_library2(int
param1, va_list args). In this case, I am stucked since I cannot hack
the library...

Here is the example :

void function_in_library(int param1, ...)

void wrapper(char* interface_name, int param1, ...) {
init_interface(interface_name);
// do all my stuff

// call function_in_library
function_in_library(param1, ...) // is it possible to do the call
without hacking the stack :)

}

int main(int argc, char **argv) {
wrapper(READ_WRITE, "here", "are", "args");
return 0;

}

Thank you

Steve
 
F

Flash Gordon

Hi guys,

I am trying to make a wrapper above a function with variable number of
arguments (called function_in_library in this example), which I cannot
modify, and for which no equivalent with va_args exist. I would like
to know if there is mean to call this function with the same arguments
of the wrapper function.
I met this issue several times and workarounded it each time making a
new function 'function_in_library2' equivalent to
'function_in_library' but with this prototype function_in_library2(int
param1, va_list args). In this case, I am stucked since I cannot hack
the library...

<snip?

In that case there is no standard solution. There *might* be a
non-standard solution, but any such solution will be highly
implementation specific, so you need to ask in a group dealing with your
specific implementation.
 
E

Eric Sosman

Hi guys,

I am trying to make a wrapper above a function with variable number of
arguments (called function_in_library in this example), which I cannot
modify, and for which no equivalent with va_args exist. I would like
to know if there is mean to call this function with the same arguments
of the wrapper function.

This is Question 15.12 in the comp.lang.c Frequently
Asked Questions (FAQ) list at <http://www.c-faq.com/>, and
you're not going to like the answer.

If you absolutely *must* do things this way, some
compilers support extensions that let you build function
calls at run-time. Whether those extensions (if they
exist) will work on the machines of interest and with
the existing (unmodifiable) library is a matter you'll
need to research for yourself. Unaided C can't do it.
 
M

moreau.steve

<snip?

In that case there is no standard solution. There *might* be a
non-standard solution, but any such solution will be highly
implementation specific, so you need to ask in a group dealing with your
specific implementation.

Yep,

I was pretty sure there was no easy solution. Anyway, thank you for
answering :)
See you,

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top