Yet another pcc botch
der Mouse
mouse at mcgill-vision.UUCP
Wed Feb 1 18:44:39 AEST 1989
In article <3310 at cbnews.ATT.COM>, lvc at cbnews.ATT.COM (Lawrence V. Cipriani) writes:
> This program demonstrates a bug that is in some versions of pcc:
> main() { float f,g; unsigned short u,v; short s,t;
> u = 250; s = 250;
> v = 100; t = 100;
> f = t - s; g = v - u;
> printf("f = %f, g = %f\n", f, g); }
[code compressed -dM]
> When compiled and executed the output is:
> f = -150.000000, g = 65386.000000
> The correct value for g is -150.000000.
That depends on the promotion rules in use. Using the "unsignedness
preserving" rules, the correct value for g is MAXUINT-149. Using the
"value preserving" rules, it depends again: if short is the same size
as int, the correct result is still MAXUINT-149; if short is smaller
than int, the correct result is -150. Your result looks like
MAXUINT-149 on a machine with 16-bit ints, of course - or a buggy
compiler. This may in fact indicate a bug in your compiler, but you
haven't given enough information to convince me of it.
der Mouse
old: mcgill-vision!mouse
new: mouse at larry.mcrcim.mcgill.edu
More information about the Comp.lang.c
mailing list