Microsoft KB Archive/71239

= BUG: Incorrect Result, No &quot;Overflow&quot; Error, in Compiled App =

Article ID: 71239

Article Last Modified on 11/21/2006



This article was previously published under Q71239



SYMPTOMS
The following code fails to give an &quot;Overflow&quot; error when compiled and run as an application, and prints an incorrect value of -32768: x% = 32767 + 1 print x%  while mouse(0)<> 1:wend An &quot;Overflow&quot; error correctly occurs when the code is run in the interpreter.

This problem occurs in Microsoft QuickBasic versions 1.00, 1.00a, and 1.00b for the Macintosh System. Microsoft is researching this problem and will post new information here when it becomes available.



MORE INFORMATION
The happens because of &quot;constant folding&quot; (also known as &quot;constant arithmetic&quot;). Constant expressions are evaluated at compile time and replaced with the result. Thus, an expression such as x% = 5 + 5 is folded by the compiler into a single assignment statement of the form x% = 10.

Thus x% = 32767 + 1 is compiled as x% = -32768. In this case, the maximum value for an integer is reached and the value gets rolled over (the sign bit gets set and a negative number is received). The expression x% = 32767 + 2 is translated to x% = -32767; the expression x% = 32767 + 3 is translated to x% = -32766; and so on.

Additional query words: MQuickB

Keywords: kbbug KB71239

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.