Udostępnij za pośrednictwem


C6313

warning C6313: Incorrect operator: Zero-valued flag cannot be tested with bitwise-and. Use an equality test to check for zero-valued flags

This warning indicates that a constant value of zero was provided as an argument to the bitwise-and (&) operator in a test context. The resulting expression is constant and evaluates to false; the result is different than intended.

This is typically caused by using bitwise-and to test for a flag that has the value zero. To test zero-valued flags, a test for equality must be performed, for example, using == or !=.

Example

The following code generates this warning:

#define FLAG 0

void f(int Flags )
{
  if (Flags & FLAG)
  {
    // code
  }
}

To correct this warning, use the following code:

#define FLAG 0

void f(int Flags )
{
  if (Flags == FLAG)
  {
    // code
  }
}