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
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

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
  }
}

Community Additions

ADD
Show:
© 2015 Microsoft