Export (0) Print
Expand All
Expand Minimize

Compiler Warning (level 3) C4800

'type' : forcing value to bool 'true' or 'false' (performance warning)

This warning is generated when a value that is not bool is assigned or coerced into type bool. Typically, this message is caused by assigning int variables to bool variables where the int variable contains only values true and false, and could be redeclared as type bool. If you cannot rewrite the expression to use type bool, then you can add "!=0" to the expression, which gives the expression type bool. Casting the expression to type bool will not disable the warning, which is by design.

The following sample generates C4800:

// C4800.cpp
// compile with: /W3
int main() {
   int i = 0;

   // try..
   // bool i = 0;

   bool j = i;   // C4800
   j++;
}
Show:
© 2014 Microsoft