Interesting Bug in Microsoft C

Ed Nilges EGNILGES at pucc.Princeton.EDU
Tue Mar 5 05:42:49 AEST 1991


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?



More information about the Comp.lang.c mailing list