Yet another pcc botch

Lawrence V. Cipriani lvc at cbnews.ATT.COM
Wed Jan 25 06:48:18 AEST 1989


In article <3310 at cbnews.ATT.COM>, I wrote:

+ This program demonstrates a bug that is in some versions of pcc:
+ 
+ main()
+ {
+ 	float f, g;
+ 	unsigned short u, v;
+ 	short s, t;
+ 
+ 	t = 100; s = 250;
+ 	v = 100; u = 250;
+ 	f = t - s; g = v - u;
+ 
+ 	printf("f = %f, g = %f\n", f, g);
+ }
+ 
+ When compiled and executed the output is:
+ 
+ f = -150.000000, g = 65386.000000
+ 
+ The correct value for g is -150.000000.  This bug is *not* present
+ in the cc that comes with SVR3 from AT&T.  It is present in SVR2 for
+ VAX and 3B20.

I consulted with the C compiler gurus in AT&T and they said that the result
as originally stated is correct, and that the value of -150.000000 is wrong.
To force the result to -150.000000 the statement:

	g = v - u;
should be:
	g = (int)v - (int)u;

Though some compilers even get this wrong, e.g., the SVR2 3b20 C compiler.
-- 
Larry Cipriani, att!cbnews!lvc or lvc at cbnews.att.com



More information about the Comp.lang.c mailing list