Passing a `va_list *'
Doug Gwyn
gwyn at smoke.BRL.MIL
Sat Oct 28 15:56:13 AEST 1989
In article <MCGRATH.89Oct27150426 at tully.Berkeley.EDU> mcgrath at tully.Berkeley.EDU (Roland McGrath) writes:
>#include <stddef.h>
That should be <stdarg.h>, of course.
> va_list args;
> ack(&args);
...
>void ack(va_list *args)
>{
> blip(va_arg(args, int **));
>}
I wonder how this could possibly have worked. va_arg() takes a va_list
as its first argument, not a va_list*. Let's assume this is a typo.
I don't have my copy of the Standard at hand at the moment, but I did
spend a lot of time working in this area, and as I recall the Standard
guarantees that you can pass the va_list to a function and continue to
use it within the function, but not necessarily a pointer to the va_list.
Upon return from the function, the va_list is "dead" until va_end()ed
and re-va_start()ed.
To answer the question of whether you can use a pointer to the va_list,
you need to consider what types are allowed for va_list. I don't recall
exactly how this ended up; it changed around a few times. The one to
watch out for is an array type.
More information about the Comp.std.c
mailing list