varargs.h

Andrew Koenig ark at alice.UUCP
Tue Feb 26 10:28:24 AEST 1985


>>As the author of varargs, I would like to set the record straight.
>>
>>The intention of varargs was that the type given to va_arg
>>should only be a type that is meaningful as a parameter.  Thus
>>char, short, and float are never meaningful because they
>>are automatically widened to int, int, and double respectively.

>There is nothing in the language that says that parameters cannot be
>declared as char, short, or float.  And if typeof is (should be!)
>added to the language, this will become all the more important.
>Since sizeof is a compile-time constant, there is no reason why
>va_arg cannot widen appropriately via ?: .  Of course, you will want an
>ifdef lint version to avoid all the "constant used in a conditional context"
>messages.  And speaking of lint, someone should fix it so it does not do
>type checking against VARARGS parameters (or maybe we need a /*VARTYPE*/
>comment?)

>-- Jim Balter, INTERACTIVE Systems (ima!jim)

Ummm -- my mistake.  I meant argument, not parameter.  Char and short
arguments are automatically cast to ints.  Float arguments are automatically
cast to doubles.  Thus there is no reason to use anything as the
second argument to va_arg except the wide types.

Yes, varargs could be changed to recognize the lengths of the narrow
types -- on some machines.  However, consider a machine where int
and float have the same size.

Anyway, even if you did manage to change varargs, all that would do
is encourage people to write "portable" programs that would only
run on the new version.  Best leave it as it is.

			--Andrew Koenig



More information about the Comp.lang.c mailing list