Date: Wed, 03 Mar 1999 12:29:02 +1000 From: Greg Black <gjb@comkey.com.au> To: cjclark@home.com Cc: freebsd-questions@FreeBSD.ORG Subject: Re: FP Math Message-ID: <19990303022902.23520.qmail@alpha.comkey.com.au> In-Reply-To: <199903021703.MAA02135@cc942873-a.ewndsr1.nj.home.com> of Tue, 02 Mar 1999 12:03:04 EST References: <199903021703.MAA02135@cc942873-a.ewndsr1.nj.home.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> 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 <stdio.h> > > 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 <float.h>), 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 <gjb@acm.org> To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990303022902.23520.qmail>