Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!haven!purdue!decwrl!decvax!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.lang.c Subject: Re: Yet another pcc botch Message-ID: <398@lakart.UUCP> Date: 23 Jan 89 14:58:47 GMT References: <3310@cbnews.ATT.COM> Organization: Lakart Corporation, Newton, MA Lines: 40 lvc@cbnews.ATT.COM (Lawrence V. Cipriani) sez: ] 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; ] ] t = 100; ] v = 100; ] ] 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. No. The correct value for g is 65386.0 [1]. If you read the gospel according to Kernighan and Ritchie [2], it says that when you do mathematics, and at least one of the operands is unsigned, and the other is NOT float or better (as above), it is done in an unsigned manner. Now last time _I_ checked, -150 was a negative number, which simply doesn't exist in the land of unsigned. HOWEVER this type conversion DOES NOT OCCUR ACROSS ASSIGNMENTS. [1] depends on your size of short. 65386.0 is correct for those with 16 bit shorts. Check your system, as your actual mileage may vary. [2] :-) -- dg@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+