FIX: Comparision with Zero Generates Bad Code

Last reviewed: January 22, 1998
Article ID: Q156913
The information in this article applies to:
  • Microsoft Visual J++ 1.0

SYMPTOMS

The 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.

CAUSE

This problem is due to bad code generated by the compiler.

WORKAROUND

Change the above code as shown below:

   int i = 0;
   boolean b = (i > 0);

STATUS

Microsoft 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 INFORMATION

The 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

REFERENCES

For the latest Knowledge Base articles and other support information on
Visual J++ and the SDK for Java, see the following page on the
Microsoft Technical Support site:

http://support.microsoft.com/support/visualj/
http://support.microsoft.com/support/java/

Keywords : CmdLnUtils
Technology : kbInetDev
Version : 1.0
Platform : WINDOWS
Issue type : kbbug
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 22, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.