Path: utzoo!utgpu!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!uwmcsd1!marque!uunet!mcvax!hp4nl!philmds!nlgvax!geertj From: geertj@nlgvax.UUCP (Geert Jan de Groot) Newsgroups: comp.unix.microport Subject: Re: Floating exception bug Summary: Use lint! Message-ID: <171@nlgvax.UUCP> Date: 2 Dec 88 22:15:40 GMT References: <1656@viper.Lynx.MN.Org> Reply-To: geertj@nlgvax.UUCP (Geert Jan de Groot) Organization: Philips Research Geldrop Lines: 58 In article <1656@viper.Lynx.MN.Org> dave@viper (David Messer) writes: >I don't know if this has been reported yet, but the following code >causes a "Floating exception error" and a core dump when run in a >system with an 80287 co-processor. >------File x.c >main() >{ > /*extern double y();*/ > for(;;) { > y() ; > } > } >------File y.c >double >y() >{ > return( 1.0 ) ; > } >------ >Compile with: > cc x.c y.c > >and execute a.out. > >The fix is to uncomment "extern double y();" in main(). Since the value >returned from y() is not used, no extern definition should be required. Not true! Functions always return values on the stack, even if the value isn't used. Thus, y() returns a double on the floating point stack. But, main() doesn't remove it because of the wrong declaration. Thus, y() _must_ be declared double. >Apparently if the function is not declared double, it uses up resources >in the floating-point chip which eventually causes an error. It was a >real bear to find because the error could occur on any floating-point >operation once the resources got too low. I used lint (On ultrix, but that doesn't matter), and it says: y value declared inconsistently y.c(3) :: x.c(5) y returns value which is always ignored Well, the second comment can be lived with, but the first predicts the trouble. Regards, geert jan de groot luc rooyakkers (on visit, not on the net) -.-.- --... ...-- -.. . .--. . .---- .... --.. --. .-.-. Geert Jan de Groot, Email: geertj@nlgvax.pcg.philips.nl Philips Research Laboratories, Packet: PE1HZG @ PI8ZAA Project Centre Geldrop, AMPRNET: [44.137.24.3] Building XR, Room 15, Willem Alexanderlaan 7B, "When in doubt, 5664 AN Geldrop, The Netherlands. tune for minimum smoke phone: +31 40 892204 and then consult a reference" [Standard disclaimers apply] -(Found in a manual)