On Wed, 20 Mar 2002, Drew Parsons wrote: > you may recall early last year I asked for help getting mirrormagic to > compile under powerpc. David Roundy provided a patch (to gadgets.c) which > appeared to fix the problem. > > Holger Schemel, the upstream author, is currently preparing a new upstream > revision and wishes to incorporate the Debian patches. However, he is > concerned about the fix we used to compile for powerpc, worried that the fix > is not platform independent.
> On Sun, Mar 17, 2002 at 09:32:18PM +0100, Holger Schemel wrote: > > Hello Drew, > > > > > Also, here is a small patch which fixes support for the powerpc > > > architecture > > > (va_arg got mixed up in gadgets.c), and sound handling when no > > > sound card is present (sound.c). > > > > > > ======================================================= > > > --- mirrormagic-2.0.0.orig/src/libgame/gadgets.c > > > +++ mirrormagic-2.0.0/src/libgame/gadgets.c > > > @@ -309,7 +309,7 @@ > > > break; > > > > > > case GDI_CHECKED: > > > - gi->checked = va_arg(ap, boolean); > > > + gi->checked = (boolean) va_arg(ap, int); > > > break; > > [...] > > > > Hm, applying this patch would mess up things for other platforms, > > because "boolean" is typedef'ed as "unsigned char". If it simply > > gets replaced by "int", va_arg reads a 16 or 32 bit value instead > > of a 8 bit value. Well, the patch should be correct ANSI C, I wonder how it worked on other architectures before. The reason is that a function with variable argument list gets called with an argument of type unsigned char, so this first is a case for "default promotion" to int. The corresponding paragraph from the glibc documentation: Since the prototype doesn't specify types for optional arguments, in a call to a variadic function the default argument promotions are performed on the optional argument values. This means the objects of type char or short int (whether signed or not) are promoted to either int or unsigned int, as appropriate; and that objects of type float are promoted to type double. So, if the caller passes a char as an optional argument, it is promoted to an int, and the function can access it with va_arg (ap, int). Cheers, Lukas