Dela via


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.

Example

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.