Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: parsing variable arg lists via va_list pointers (any gurus here?)

Reply
Thread Tools

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

 
 
Amandil
Guest
Posts: n/a
 
      06-03-2008
On Jun 2, 10:23 pm, Jesse Ziser <(E-Mail Removed)> 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_o f_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
 
Reply With Quote
 
 
 
 
Peter Nilsson
Guest
Posts: n/a
 
      06-04-2008
On Jun 4, 1:20*am, Amandil <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: parsing variable arg lists via va_list pointers (any gurus here?) Chris Dollin C Programming 4 06-04-2008 01:56 PM
Re: parsing variable arg lists via va_list pointers (any gurus here?) Tomás Ó hÉilidhe C Programming 2 06-04-2008 12:33 PM
How to pass a multiline arg to exec('some.exe arg')? n00m Python 5 05-05-2008 02:58 PM
Trouble with setTimeout(arg, arg) nat.hourt@gmail.com Javascript 7 11-12-2005 05:13 PM
Modifying an arg of va_list Jon C Programming 7 07-15-2005 07:12 AM



Advertisments