Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!uunet!mcsun!ukc!pyrltd!datcon!sar From: sar@datcon.UUCP (Simon A Reap) Newsgroups: comp.lang.c Subject: Re: Is this a bug in Turbo C 2.0? Message-ID: <60@datcon.UUCP> Date: 8 Mar 90 16:50:11 GMT References: <3210@pur-phy> Reply-To: sar@datcon.co.uk (Simon A Reap) Organization: Data Connection Limited, Enfield, Middlesex, UK Lines: 17 In article <3210@pur-phy> murphy@newton.physics.purdue.edu.UUCP (William J. Murphy) writes: >long SUM; >short data1, data2, data3, data4, data5; >SUM = data1 + data2 + data3 + data4 + data5; >Here is the problem, when the sum of data? < 32767 it sums correctly on both >GNU C and TC. Hwen the sum of data? > 32767, TC does the rollover and >becomes negative while GNU C carries the sum as a long and returns the : >SUM = (long)data1 + (long)data2 + (long)data3 + (long)data4 + (long)data5; >solved the problem. Microsoft C 5.1 (under OS/2) does the same (wrong) thing. BTW, you only need to (long) cast one of the data? to get the right result. -- Enjoy, yerluvinunclesimon Opinions are mine - my cat (1CC) has her own ideas Reach me at sar@datcon.co.uk, or ...!mcvax!ukc!pyrltd!datcon!sar