Share via


C6285

warning C6285: (<non-zero constant> || <non-zero constant>) is always a non-zero constant. Did you intend to use the bitwise-and operator?

This warning indicates that two constant values, both greater than one, were detected as arguments to a logical-or operation that occurs in a test context. This expression is always TRUE.

Constant values greater than one suggest that the arguments to logical-or could be bit fields. Consider whether a bitwise operator, &, might be a more appropriate operator in this case.

Example

The following code generates this warning:

#include <stdio.h>
#define     TESTED_VALUE    0x37
#define     MASK            0xaa

void f()
{
  if (TESTED_VALUE || MASK) 
  {
    puts("(TESTED_VALUE || MASK) True");
    // code...
  }
  else 
  {
    puts("(TESTED_VALUE || MASK) False");
    // code...
  }
}

To correct this warning, use the bitwise-AND (&) operator as shown in the following code:

#include <stdio.h>
#define     TESTED_VALUE    0x37
#define     MASK            0xaa

void f(int flag)
{
  if ((TESTED_VALUE & MASK)== flag)
  {
    puts("true");
    // code...
  }
  else
  {
    puts("false");
    // code...
  }
}

See Also

Reference

Bitwise AND Operator: &

Logical OR Operator: ||

Compiler Warning (level 4) C4127