Our organization has a required coding rule (without any explanation) that:
if … else if constructs should be terminated with an el
Well, my example involves undefined behavior, but sometimes some people try to be fancy and fails hard, take a look:
int a = 0;
bool b = true;
uint8_t* bPtr = (uint8_t*)&b;
*bPtr = 0xCC;
if(b == true)
{
a += 3;
}
else if(b == false)
{
a += 5;
}
else
{
exit(3);
}
You probably would never expect to have bool
which is not true
nor false
, however it may happen. Personally I believe this is problem caused by person who decides to do something fancy, but additional else
statement can prevent any further issues.