bool, , bool, bool , bool - . " "? , , :
#define FLAG_A 0x00000001
#define FLAG_B 0x00000002
...
#define FLAG_F 0x00000020
struct S
{
unsigned int flags;
};
void doSomething(S* sList, bool withF)
{
for (S* s = sList; s; s = s->next)
{
if ((bool)(s->flags & FLAG_F) != withF)
continue;
}
}
since it (bool)(s->flags & FLAG_F)can be used to evaluate either 0 or 1. If it was boolinstead boolof throwing, it would not work, because it withFevaluates to 0 or 1, but (bool)(s->flags & FLAG_F)0 or the numeric value FLAG_F, which in this case is not equal to 1.
This example is far-fetched, yes, but real errors of this type can and do happen too often in old code that does not use the true Boolean types C99 / C ++.
source
share