Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

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.

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 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 ...
  }
}
Show:
© 2015 Microsoft