From owner-freebsd-questions Tue Mar 2 18:31:38 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 DE61B14E48 for ; Tue, 2 Mar 1999 18:31:13 -0800 (PST) (envelope-from gjb@comkey.com.au) Received: (qmail 23521 invoked by uid 1001); 3 Mar 1999 02:29:02 -0000 Message-ID: <19990303022902.23520.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: Wed, 03 Mar 1999 12:29:02 +1000 From: Greg Black To: cjclark@home.com Cc: freebsd-questions@FreeBSD.ORG Subject: Re: FP Math References: <199903021703.MAA02135@cc942873-a.ewndsr1.nj.home.com> In-reply-to: <199903021703.MAA02135@cc942873-a.ewndsr1.nj.home.com> of Tue, 02 Mar 1999 12:03:04 EST Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > Example: Here are two quick C program that I think show why I am > confused. The first produces an exception and core dumps (for me > anyway). In this one, I have set floats to values outside of their > range. It dumps at the point marked, This question has nothing at all to do with FreeBSD (or any OS) and everything to do with a failure to understand the rules of the C language, so I'll keep this very short. > #include > > int main() > { > float a = -1.0e-41; At this point your program has entered the domain of undefined behaviour and from here on the compiler is free to do absolutely anything it likes, including generating the code represented by the following fragment: execl("/bin/rm", "rm", "-rf", "/", 0); If you assign a double constant to a float and that constant is outside the range of the float (as defined precisely in the header ), then the behaviour is undefined. This also means that the program is allowed to appear to get some things right, but gives you no right to expect that. As for why anybody would deliberately do something like this, given its complete uselessness, that's another question. In short, the answer is: "you can't do that." > Could someone explain this? Done. > [Should I send this to -hackers instead?] Absolutely not. Anybody who wants or needs further illumination should either get and read the C Standard or visit comp.lang.c (if it still exists). -- Greg Black To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message