From owner-freebsd-questions Fri Mar 19 7:45: 7 1999 Delivered-To: freebsd-questions@freebsd.org Received: from alpha.comkey.com.au (alpha.comkey.com.au [203.9.152.215]) by hub.freebsd.org (Postfix) with SMTP id A6553151A9 for ; Fri, 19 Mar 1999 07:44:42 -0800 (PST) (envelope-from gjb@comkey.com.au) Received: (qmail 18704 invoked by uid 1001); 19 Mar 1999 14:39:05 -0000 Message-ID: <19990319143905.18703.qmail@alpha.comkey.com.au> X-Posted-By: GBA-Post 1.04 06-Feb-1999 X-PGP-Fingerprint: 5A91 6942 8CEA 9DAB B95B C249 1CE1 493B 2B5A CE30 Date: Sat, 20 Mar 1999 00:39:05 +1000 From: Greg Black To: spinner.rflab@t-online.de (Steffen Hein) Cc: freebsd-questions@FreeBSD.ORG Subject: Re: gnu C compiler References: <36EFA9ED.5126E95C@t-online.de> <19990317210724.9018.qmail@alpha.comkey.com.au> <36F24371.37ACAF58@t-online.de> In-reply-to: <36F24371.37ACAF58@t-online.de> of Fri, 19 Mar 1999 12:30:41 GMT Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > > How can you explain me that the same gnu C compiler ( release 2.7.2.1 ) > > > in FreeBSD apparently does not handle the long double format correctly > > > while in Linux it does ? > > > Learn to use gcc's warnings (at the very least -Wall), and > > you'll see where your code is incorrect. > > > printf( "\n LDBL_MIN = % Le ", LDBL_MIN ); > > > > This is wrong, as gcc would have told you with -Wall: you are > > passing a `double' to printf() but telling it you are passing a > > `long double'. If you lie to the compiler, then it will get its > > revenge. > > > > If you cast LDBL_MIN and friends to the correct type, then your > > program will run to completion. > > The comment merely states that the gnu C compiler does not comply here > with the ANSI standard, according to which the format instructions are > legitimate. You don't understand the Standard. In your code, you have used the "%Le" conversion, which specifies that the relevant argument will be a `long double'. However, the argument you provide, in this particular example `LDBL_MIN', is -- despite its name -- not a `long double' but a plain `double'. The only way to make it the correct `long double' type is with a cast, e.g.: printf( "\n LDBL_MIN = % Le ", (long double) LDBL_MIN ); > ( Cf. chapter 'The ANSI Runtime Library' in Darnell & Margolis, ISBN > 0-387-97389-3, p.453, Springer ) I use the Standard, since other people's interpretations are frequently wrong. > - At any rate, Linux cooperates correctly. I have never seen the Linux file, so I don't know how it defines `LDBL_MIN'. In any case, the Standard leaves the definition somewhat open: it's an implementation-defined expression whose value must be equal to or less than 1e-37. The FreeBSD header has: #define DBL_MIN 2.2250738585072014E-308 #define LDBL_MIN DBL_MIN Those two lines comply with the Standard. Note that, if the second line was: #define LDBL_MIN 2.2250738585072014E-308L your code would have been correct since, in this imaginary definition, `LDBL_MIN' is a `long double'. But, since the real definition has it as a `double', your code is wrong under FreeBSD (and unwise under any implementation). It's a mistake to imagine that the C Standard aims to be fully prescriptive about the details of all these values. You have to actually check them for each implementation, because the details are specified as `implementation-defined'. -- Greg Black To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message