FIX: Comparision with Zero Generates Bad CodeLast reviewed: January 22, 1998Article ID: Q156913 |
The information in this article applies to:
SYMPTOMSThe following code sets the Boolean to true, whereas the correct value is false:
int i = 0; boolean b = (0 < i);b is set to true.
CAUSEThis problem is due to bad code generated by the compiler.
WORKAROUNDChange the above code as shown below:
int i = 0; boolean b = (i > 0); STATUSMicrosoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. This problem has been fixed in Visual J++ 1.1.
MORE INFORMATIONThe problem occurs only when 0 is the literal on the left side of the operator. If the left side of the operator is a variable or a literal other than 0, then the expression is evaluated correctly. The following expressions are evaluated correctly:
int i = 0; int j = 0; boolean b = (i < j); i++; b = (1 < i);Some of the common places where you might run into this bug are in conditional statements or loops. Steps to Reproduce Problem Use the following code to reproduce the problem:
int i = 0; boolean b = (0 < i); |
Additional query words: comparison
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |