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

C6315

warning C6315: Incorrect order of operations: bitwise-and has higher precedence than bitwise-or. Add parentheses to clarify intent

This warning indicates that an expression in a test context contains both bitwise-and (&) and bitwise-or (|) operations, but causes a constant because the bitwise-or operation happens last. Parentheses should be added to clarify intent.

The following code generates this warning:

void f( int i )
{
  if ( i & 2 | 4 ) // warning
  {
    // code
  }
}

To correct this warning, add parenthesis as shown in the following code:

void f( int i )
{
  if ( i & ( 2 | 4 ) )
  {
    // code
  }
}
Show:
© 2015 Microsoft