Style guides and portability

Karl Heuer karl at ima.isc.com
Sat Jan 19 04:10:54 AEST 1991


In article <1332 at geovision.UUCP> pt at geovision.gvc.com writes:
>Simple, you cast all your integer types to long, and printf them as %ld.

This is probably the least clumsy solution.

>If I remember correctly, variadic functions are type promoted the same way
>classic C functions are

Yes, the default argument-widening rules apply to the non-fixed arguments.

>[i.e.] integer types are promoted to long,

But that isn't one of them.  Small types will widen as far as (signed or
unsigned) int, but nothing smaller than long will widen to long.%

>[so] the cast probably isn't even needed

Conclusion fails due to faulty premise.  The cast is in fact required.

(Note that this is not

>Anybody know what happens to "long double" types in variadic functions, or
>is "long double" not an ANSI-C type?

It is.  A float promotes to double, but double and long double stay as-is.  So
there is no printf format for float; "%f" means double (including a widened
float); "%Lf" means long double.  "%lf" is an illegal format, though many
implementations treat it as identical to "%f".

Karl W. Z. Heuer (karl at ima.isc.com or uunet!ima!karl), The Walking Lint
________
% Mixing an int with a long in an expression such as i+li will cause the int
  to be promoted to long by the "usual arithmetic conversions", but that isn't
  what we're talking about here.



More information about the Comp.lang.c mailing list