varargs question: va_list in structure

Discussion in 'C Programming' started by Rick Anderson, May 19, 2006.

  1. I want to store a "va_list" in a structure (which gets passed around
    from function to function). I cannot use the va_copy() routine
    to create a copy of the varargs (it looks like it uses stack memory).

    Has anyone written some portable code to create a copy of the varargs
    information, and subsequent routines to retrieve the varargs information?

    Thanks in advance!
    Rick
    Rick Anderson, May 19, 2006
    #1
    1. Advertising

  2. Rick Anderson

    Richard Bos Guest

    Rick Anderson <> wrote:

    > I want to store a "va_list" in a structure (which gets passed around
    > from function to function). I cannot use the va_copy() routine
    > to create a copy of the varargs (it looks like it uses stack memory).
    >
    > Has anyone written some portable code to create a copy of the varargs
    > information,


    Yes; it's called va_copy().

    Otherwise, the contents of a va_list are entirely system-dependent. The
    Standard says nothing about its layout; all it specifies is how one may
    be used.

    Richard
    Richard Bos, May 22, 2006
    #2
    1. Advertising

  3. On Fri, 19 May 2006 18:41:07 GMT, Rick Anderson
    <> wrote:

    > I want to store a "va_list" in a structure (which gets passed around
    > from function to function). I cannot use the va_copy() routine
    > to create a copy of the varargs (it looks like it uses stack memory).
    >

    What do you mean 'looks like'? Do you just mean the syntax looks like
    a function call? It needn't be, and IME never is. Each of the
    va_list's will certainly occupy space, but if you want to have them
    there's no way around that.

    > Has anyone written some portable code to create a copy of the varargs
    > information, and subsequent routines to retrieve the varargs information?
    >

    va_list is permitted to be location dependent in an unspecified
    fashion = dependent on the implementation and undocumented, so no one
    could possibly write fully Standard code to do this. That's why
    va_copy exists.

    On all implementations I know of either a bitwise copy with memcpy
    (for array) or an assignment (otherwise) works. But any implementation
    where va_copy is provided and does something which is less efficient
    than (whichever of) those, is so badly done I wouldn't trust it for
    int main ( void ) { return 0; }

    Or, do you actually need to copy? Can you just va_start the one in
    your structure to start with?

    - David.Thompson1 at worldnet.att.net
    Dave Thompson, May 29, 2006
    #3
    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. Chris Uppal

    Varargs

    Chris Uppal, Jan 19, 2005, in forum: Java
    Replies:
    4
    Views:
    511
    Chris Uppal
    Jan 20, 2005
  2. =?iso-8859-1?B?bW9vcJk=?=

    ArrayList to Varargs

    =?iso-8859-1?B?bW9vcJk=?=, Dec 12, 2005, in forum: Java
    Replies:
    1
    Views:
    1,234
  3. Ian Partridge

    passing varargs to another function

    Ian Partridge, Dec 24, 2003, in forum: C Programming
    Replies:
    2
    Views:
    764
    Derk Gwen
    Dec 24, 2003
  4. Replies:
    5
    Views:
    460
    metaperl
    Sep 15, 2006
  5. Mike
    Replies:
    5
    Views:
    342
    Daniel Pitts
    Apr 18, 2007
Loading...

Share This Page