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

Discussion in 'C Programming' started by moreau.steve@gmail.com, Dec 30, 2008.

  1. Guest

    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
     
    , Dec 30, 2008
    #1
    1. Advertising

  2. Flash Gordon Guest

    wrote:
    > 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.
    --
    Flash Gordon
     
    Flash Gordon, Dec 30, 2008
    #2
    1. Advertising

  3. Eric Sosman Guest

    wrote:
    > 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.

    --
    Eric Sosman
    lid
     
    Eric Sosman, Dec 30, 2008
    #3
  4. Guest

    On 30 déc, 17:22, Flash Gordon <> wrote:
    > wrote:
    > > 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.
    > --
    > Flash Gordon


    Yep,

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

    Steve
     
    , Dec 31, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Walters
    Replies:
    2
    Views:
    543
    Ben Pfaff
    Feb 13, 2004
  2. Ross A. Finlayson
    Replies:
    19
    Views:
    650
    Keith Thompson
    Mar 10, 2005
  3. Replies:
    2
    Views:
    366
    Dave Thompson
    Feb 27, 2006
  4. Replies:
    5
    Views:
    385
  5. rashmi
    Replies:
    6
    Views:
    419
    rashmi
    Dec 7, 2006
Loading...

Share This Page