Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

C6288

warning C6288: Incorrect operator: mutual inclusion over && is always zero. Did you intent to use || instead?

This warning indicates that in a test expression, a variable is being tested against two different constants and the result depends on both conditions being true. The code in these cases indicates that the programmer's intent is not captured correctly. It is important to examine the code and correct the problem; otherwise your code will not behave the way you expected it to.

This problem is generally caused by using &&; in place of ||, but can also be caused by using == where != was intended.

The following code generates this warning:

void f(int x)
{
  if ((x == 1) && (x == 2)) // warning
  {
    // code ...
  }
}

To correct this warning, use the following code:

void f(int x)
{
     if ((x == 1) || (x == 2)) 
     {
          // logic
     }
    
    /* or */
    if ((x != 1) && (x != 2))
    {
        // code ...
    }
}

The analysis tool does not warn if the expression has side effects.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.