Path: utzoo!attcan!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!osu-cis!att!cbnews!lvc From: lvc@cbnews.ATT.COM (Lawrence V. Cipriani) Newsgroups: comp.lang.c Subject: Re: Yet another pcc botch Summary: not really a bug Keywords: Compiler bugs Message-ID: <3441@cbnews.ATT.COM> Date: 24 Jan 89 20:48:18 GMT References: <3310@cbnews.ATT.COM> Organization: AT&T Bell Laboratories Lines: 36 In article <3310@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@cbnews.att.com