Floating exception bug

Geert Jan de Groot geertj at nlgvax.UUCP
Sat Dec 3 08:15:40 AEST 1988


In article <1656 at viper.Lynx.MN.Org> dave at 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 at 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)	



More information about the Comp.unix.microport mailing list