Re: parsing variable arg lists via va_list pointers (any gurus here?)

Discussion in 'C Programming' started by Amandil, Jun 3, 2008.

  1. Amandil

    Amandil Guest

    On Jun 2, 10:23 pm, Jesse Ziser <> wrote:
    > Hello,
    >
    > I'm trying to write a function that takes a very complex variable
    > argument list. It is so complex, in fact, that it can only be parsed by
    > calling a bunch of functions, each of which parses another little piece
    > of the argument list. In order to do that, I need to do something
    > weird, and I don't know if there exist any systems that won't like this
    > weirdness. I hope someone can point out any such systems.
    >
    > To parse each chunk of the argument list, I will need to pass a va_list
    > to some function, and that function will need to step the va_list object
    > over the arguments it parses so that it points at the next argument to
    > parse when it returns. ANSI says that when you pass a va_list object to
    > a function and call va_arg() on it within that function, the value of
    > the va_list object is undefined upon return. Behold:
    >
    > void parse_half_of_arg_list( va_list args )
    > {
    > ...
    > foo_t x = va_arg( args, foo_t );
    > bar_t y = va_arg( args, bar_t );
    > ...
    >
    > }
    >
    > void superfunc( int a, ... )
    > {
    > va_list args;
    >
    > va_start( args, a );
    >
    > parse_half_of_arg_list( args );
    > /* Uh-oh! ANSI says args is undefined now,
    > but there's still more to parse */
    > parse_half_of_arg_list( args );
    >
    > va_end( args );
    >
    > }
    >


    Here's an idea, though if it doesn't help you, it probably means that
    I didn't understand your question properly. How about each parsing
    function returns the va_list object after it's done with it. For
    example, instead of
    void parse_half_of_arg_list( va_list *args )
    {
    ...
    foo_t x = va_arg( *args, foo_t );
    bar_t y = va_arg( *args, bar_t );
    ...
    }
    You could try
    va_list parse_half_of_arg_list(va_list args)
    {
    ...
    foo_t x = va_arg(args, foo_t);
    ...
    return args;
    }

    If you already return something else from one of those
    interminably_long_function_names_that_parse_part_of_the_list()'s then
    this idea might not work. Or this may have already occured to you and
    you decided not to use it for reasons not yet clear to me.

    -- Marty Wolfe
     
    Amandil, Jun 3, 2008
    #1
    1. Advertising

  2. On Jun 4, 1:20 am, Amandil <> wrote:
    > How about each parsing function returns the va_list
    > object after it's done with it.
    > ...
    > You could try
    >   va_list parse_half_of_arg_list(va_list args)
    >   {


    That violates a constraint on implementations where
    va_list is an array.

    --
    Peter
     
    Peter Nilsson, Jun 4, 2008
    #2
    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. Jon

    Modifying an arg of va_list

    Jon, Jul 14, 2005, in forum: C Programming
    Replies:
    7
    Views:
    607
  2. n00m
    Replies:
    5
    Views:
    413
  3. Tomás Ó hÉilidhe
    Replies:
    2
    Views:
    527
    Bartc
    Jun 4, 2008
  4. Chris Dollin
    Replies:
    4
    Views:
    290
    Chris Dollin
    Jun 4, 2008
  5. Replies:
    7
    Views:
    204
Loading...

Share This Page