Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!udel!princeton!pucc!EGNILGES From: EGNILGES@pucc.Princeton.EDU (Ed Nilges) Newsgroups: comp.lang.c Subject: Interesting Bug in Microsoft C Message-ID: <12541@pucc.Princeton.EDU> Date: 4 Mar 91 19:42:49 GMT Reply-To: EGNILGES@pucc.Princeton.EDU Organization: Princeton University, NJ Lines: 18 Disclaimer: Author bears full responsibility for contents of this article A colleague wrote a program containing the value -2,147,483,648L (-2**31) which compiled and ran on Borland Turbo-C but produced a diagnostic "con- stant to long" on Microsoft QuickC. When he changed it, replacing the value with -2,147,483,647L - 1 the program ran on QuickC. I think what is happening is this. The compiler is evaluating con- stants in the lexical analysis phase by (in the case of -2**31) not- ing the sign, then grabbing each decimal digit, shifting the old value by multiplying by ten, and adding the next digit to the old value. This algorithm has a bug. It generates the value 2**31 which is too large for a long integer. I'm sure that others have bumped into this bug, soooo... 1. Is this diagnosis correct? 2. If so, when will Microsoft fix this problem?