C++ rely on implicit conversion to bool in conditions?

c++, coding-style, implicit-conversion

Solution

In the strictest sense, you can rely on implicit conversions to bool. Backwards compatibility with C demands it.

Thus it becomes a question of code readability. Often the purpose of code standards is to enforce a sameness to the code style, whether you agree with the style or not. If you're looking at someone else's standard and wondering if you should incorporate it into your own, go ahead and debate it - but if it's your company's long-standing rule, learn to live with it.

P.S. I just joined an organization that has the same rule. I'm actually fine with it because I've always believed that explicit is better than implicit. The one thing I can't abide though is `bool condition; ... if (condition == true)`, which so redundant that it grates on my eyes.

Any decent compiler should generate the same code whether the check is implicit or explicit, so that shouldn't be a consideration.

Problem

I found the following rule in a coding standards sheet : Do not rely on implicit conversion to bool in conditions. if (ptr) // wrong if (ptr != NULL) // ok How reasonable/usefull is this rule? How much overload on the compiled code?

Original source