Is this a bug in Turbo C 2.0?
Simon A Reap
sar at datcon.UUCP
Fri Mar 9 02:50:11 AEST 1990
In article <3210 at pur-phy> murphy at 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 at datcon.co.uk, or ...!mcvax!ukc!pyrltd!datcon!sar
More information about the Comp.lang.c
mailing list