On Jun 2, 10:23 pm, Jesse Ziser <d...@spam.die> 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
|