Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!ima!dirtydog!karl From: karl@ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Style guides and portability Message-ID: <1991Jan18.171054.7193@dirtydog.ima.isc.com> Date: 18 Jan 91 17:10:54 GMT References: <14824@smoke.brl.mil> <1991Jan13.182655.17672@athena.mit.edu> <1332@geovision.UUCP> Sender: news@dirtydog.ima.isc.com (NEWS ADMIN) Reply-To: karl@dirtydog (Karl Heuer) Organization: Interactive Systems Lines: 34 In article <1332@geovision.UUCP> pt@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@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.