reference to va_list

Discussion in 'C++' started by Rich Herrick, Jan 16, 2005.

  1. Rich Herrick

    Rich Herrick Guest

    Is it defined behavior to use a reference to a va_list to allow calling a
    function to extract arguments from the argument list, then upon returning to
    the calling function, continue extracting additional arguments. For
    example:

    int foo2(va_list& list)
    {
    return int(va_arg(list, int));
    }

    void foo(int x, ...)
    {
    va_list list;

    va_start(list, x);
    int a = foo2(list);
    int b = int(va_arg(list, int));
    va_end(list);

    printf("%d %d %d\n", x, a, b);
    }

    Ignoring why someone would do this, would calling foo(1, 2, 3) print the
    values of the three variables x, a, and b as 1, 2, and 3, respectively?

    Thanks,

    --
    Rich Herrick
    http://www.richherrick.com
     
    Rich Herrick, Jan 16, 2005
    #1
    1. Advertisements

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. va_list in JNI

    , Jun 23, 2005, in forum: Java
    Replies:
    4
    Views:
    2,986
  2. Peter

    va_list help, please ...

    Peter, Feb 15, 2005, in forum: C++
    Replies:
    6
    Views:
    3,812
    Pete Becker
    Feb 15, 2005
  3. John Guo

    va_list help

    John Guo, Mar 31, 2005, in forum: C++
    Replies:
    5
    Views:
    3,486
    Pete Becker
    Mar 31, 2005
  4. Douwe
    Replies:
    3
    Views:
    974
    Chris Torek
    Aug 30, 2003
  5. Shea Martin

    passing a va_list to sprintf

    Shea Martin, Oct 31, 2003, in forum: C Programming
    Replies:
    3
    Views:
    1,009
    Shea Martin
    Oct 31, 2003
  6. Old Wolf

    Reusing a va_list

    Old Wolf, Jan 23, 2004, in forum: C Programming
    Replies:
    4
    Views:
    647
    Michael Wojcik
    Jan 23, 2004
  7. Vaclav Haisman
    Replies:
    2
    Views:
    1,515
    Vaclav Haisman
    May 15, 2010
  8. Urs Thuermann

    Passing va_list by reference to a function

    Urs Thuermann, Nov 22, 2010, in forum: C Programming
    Replies:
    7
    Views:
    2,435
    Urs Thuermann
    Nov 23, 2010
Loading...