Warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)

user3157184 picture user3157184 · Jan 4, 2014 · Viewed 30.5k times · Source

I have this problem in my code:

bool CBase::isNumber()
{
return (id & MID_NUMBER);
}

bool CBase::isVar()
{
return (id & MID_VARIABLE);
}

bool CBase::isSymbol()
{
return (id & MID_SYMBOL);
}

Answer

Marco A. picture Marco A. · Jan 4, 2014

FYI: Casts won't hide the warning by design.

Something like

return (id & MID_NUMBER) != 0;

should clearly state "I want to check whether this value is zero or not" and let the compiler be happy