Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!purdue!mentor.cc.purdue.edu!pur-ee!pur-phy!murphy From: murphy@pur-phy (William J. Murphy) Newsgroups: comp.lang.c Subject: Is this a bug in Turbo C 2.0? Message-ID: <3210@pur-phy> Date: 6 Mar 90 15:28:21 GMT Reply-To: murphy@newton.physics.purdue.edu.UUCP (William J. Murphy) Organization: Purdue Univ. Physics Dept., W. Lafayette, IN Lines: 22 Yesterday, I was debugging a program of mine and came across an interesting difference between GNU C and Turbo C. Here is the buggy code: 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 correct answer. Which one is correct? (according to ANSI standards) Of course the fix is simple, but the rest of the program had problems that are not so simple to fix under MSDOS. SUM = (long)data1 + (long)data2 + (long)data3 + (long)data4 + (long)data5; solved the problem. -- Bill Murphy murphy@newton.physics.purdue.edu Enjoying my Amiga 2000, but holding out for a real computer: The Amiga 3000!!