Re: va_lists in glib/gtk and set/get(...) functions



On Sat, 22 Aug 1998, Tor Lillqvist wrote:

> > i'll therefore go through gtk and glib and change the
> > void func ([some args], va_list *args1, va_list *args2)
> > {
> > }
> > prototypes to
> > void func ([some args], va_list args1)
> > {
> >   va_list arg2 = args1;
> > }
> 
> Not so fast... This will not compile if va_list is defined as: 
>  typedef char *va_list[0] .
> 
> In that case you would have to use the (totally implementation-dependent) 
>  char  **arg2 = args1;

yep, and because it is implementation dependant, every stdarg implementation
provides this as well (the compiler needs to know ho to copy va_list, since
it passes it to a function by value).

> But hmm, I'm not 100% sure if that will have the desired effect.
> (Well, when I changed gtk like this, at least I don't get the invalid
> cast etc warnings any more.)

take a look at the stdarg.h implementations for gcc on various systems,
they all provide __va_copy() for the compiler, e.g.

stdarg.h:#define __va_copy(dest, src) (dest) = (src)
va-ppc.h:#define __va_copy(dest, src) *(dest) = *(src)
varargs.h:#define __va_copy(dest, src) (dest) = (src)

so statements like

va_list x;
va_list y = x;

is properly taken care about as well.

> 
> --tml
> 

---
ciaoTJ



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