Re: va_list and gtk



On Fri, 21 Aug 1998, Tor Lillqvist wrote:

> Apparently having va_list be an array type is quite legal, see for
> instance http://www.spots.ab.ca/~i/c/stdarg.html. (This page just
> happened to be returned by an AltaVista search.) This is a bit
> strange as this means that the following simple program works
> differently with compilers where va_list is an array.
> 
> #include <stdio.h>
> #include <stdarg.h>
> 
> void
> zap(va_list *ap)
> {
>   int k;
>   k = va_arg(*ap, int);
>   printf("zap: got k = %d\n", k);
> }
> 
> void
> bar(va_list ap)
> {
>   int k;
>   k = va_arg(ap, int);
>   printf("bar: got k = %d\n", k);
> }
> 
> void
> ugh(va_list ap)
> {
>   zap(&ap);
> }
> 
> void
> foo(int i, ...)
> {
>   va_list ap;
> 
>   va_start(ap, i);
>   bar(ap);
>   bar(ap);
>   va_end(ap);
> 
>   va_start(ap, i);
>   ugh(ap);
>   va_end(ap);
> 
>   va_start(ap, i);
>   zap(&ap);
>   zap(&ap);
>   va_end(ap);
> }
> 
> main(int argc, char **argv)
> {
>   foo(42, 567, 789, 890);
>   return 0;
> }
> 
> When compiled with MSVC 5.0 (on NT) or gcc (on HP-UX or NT), this
> program prints:
> 
> bar: got k = 567
> bar: got k = 567
> zap: got k = 567
> zap: got k = 567
> zap: got k = 789
> 
> When compiled with Watcom 10.6, the compiler warns about line (23):
> "Warning! W100: Parameter 1 contains inconsistent levels of
> indirection", but still compiles it, and the program prints:
> 
> bar: got k = 567
> bar: got k = 789
> zap: got k = 1244844
> zap: got k = 567
> zap: got k = 789

yep, this is basically the effect i got reported in the bug report
that i wrote abou tin my previous mail.
basically the arry contents seemed cluttered on that machine.

> 
> --tml
> 

---
ciaoTJ




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]