Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: comp.lang.c Subject: Re: Yet another pcc botch Keywords: Compiler bugs Message-ID: <1415@mcgill-vision.UUCP> Date: 1 Feb 89 08:44:39 GMT References: <3310@cbnews.ATT.COM> Organization: McGill University, Montreal Lines: 27 In article <3310@cbnews.ATT.COM>, lvc@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@larry.mcrcim.mcgill.edu