PREfast Warning 290 (Windows CE 5.0)
290 - Bitwise operation on logical result.
Additional Information: ! has higher precedence than &.
Recommended Fix: Use && or (!(x & y)) instead
This warning indicates a problem with a bitwise operation.
The ! operator yields a Boolean result, and the & (bitwise-AND) operator takes two arithmetic arguments. The ! operator also has higher precedence than &.
One of the following errors has been detected:
The expression uses parentheses incorrectly.
Because the result of ! is Boolean (zero or one), an attempt to test that two variables have bits in common ends up only testing that the lowest bit is present in the right side: ((!8) & 1) == true.
The ! operator is incorrect, and should be a ~ instead.
The ! operator has a Boolean result, while the ~ operator has an arithmetic result. These operators are only interchangeable when operating on a Boolean value (0 or 1): ((!0x01) & 0x10) == 0x0, while ((~0x01) & 0x10) == 0x10.
The binary operator & is incorrect, and should instead be &&.
Although & can sometimes be interchanged with &&, it is neither equivalent nor efficient because it forces evaluation of the right side of the expression. Some side effects in this sort of expression can be terminal.
This warning is not reported if the ! operator is on the left side of the & operator, because this case is typically the relatively benign case of an incorrect operator.
It is difficult to judge the severity of this problem without examining the code. The code should be inspected to ensure that the intended test is occurring.
This warning always indicates possible confusion in the use of an operator or operator precedence.
Example
Defective Source
if (!x & y) {;}
Corrected Source
// When testing that x has no bits in common with y.
if (!(x & y)) {;}
// When testing for the complement of x in y.
if ((~x) & y) {;}
// When y is a Boolean or Boolean result.
if ((!x) && y) {;}
Send Feedback on this topic to the authors