This documentation is archived and is not being maintained.

Compiler Warning (level 1) C4807

Error Message

'operation' : unsafe mix of type 'type' and signed bitfield of type 'type'

This warning is generated when comparing a one-bit signed bit field to a bool variable. Because a one-bit, signed bit field can only contain the values -1 or 0, it is dangerous to compare it to bool. No warnings are generated about mixing bool and one-bit, unsigned bitfields since they are identical to bool and can only hold 0 or 1.


The following sample generates C4807:

// C4807.cpp
// compile with: /W1
typedef struct bitfield {
   signed mybit : 1;
} mybitfield;

int main() {
   mybitfield bf;
   bool b = true;

   // try..
   // int b = true;

   bf.mybit = -1;
   if (b == bf.mybit) {   // C4807
      b = false;