Re: Strange ipfw change (Sparc bugfix?)

Alan Modra (alan@spri.levels.unisa.edu.au)
Thu, 10 Sep 1998 17:22:21 +0930 (CST)


On Thu, 10 Sep 1998, pacman wrote:

> Alan Modra writes the following:
> >gcc indeed knows that a short, char, float etc are promoted. Check
> >stdarg.h or varargs.h. You'll see that the size of the requested type is
> >rounded up as necessary. No problem.
>
> :r!head -5 /usr/lib/gcc-lib/i386-redhat-linux/2.7.2.3/include/stdarg.h
>
> /* stdarg.h for GNU.
> Note that the type used in va_arg is supposed to match the
> actual type **after default promotions**.
> Thus, va_arg (..., short) is not valid. */
>
> Hmm... The header seems to be confirming what I said :)

Never believe comments. :-)

> Looking further down, I see some ugly macros that may be designed to cover up
> the error of calling va_arg(foo, short), but these seem like a bad idea to me
> since it is an error that's just as easily fixed as covered up...

There's lots of gotchas when trying to write reasonably portable var args
code. Notice the sysV68 special case for __va_rounded_size. This would
indicate that shorts are *not* promoted to ints for sysV68 var args
functions. Errk.

The safest thing is to explicitly promote args when calling the var arg
function, and then use the promoted type within the function.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/faq.html