PREfast Warning 299 (Windows CE 5.0)
299 - Explicitly comparing a bit field to a Boolean will yield unexpected results.
This warning indicates an incorrect assumption that Booleans and bitfields are equivalent.
Assigning 1 to bitfields places 1 in its single bit; however, comparison of this bitfield to 1 includes an implicit cast of the bitfield to a signed int. This cast converts the stored 1 to a -1 and the comparison can yield unexpected results.
Example
Defective Source
if (a.flag == 1 /* == TRUE */) {
// Will not execute
;
}
Corrected Source
if (a.flag) {
// May execute
;
}
Send Feedback on this topic to the authors