On 2014-11-16 05.22, Timo Kreuzer wrote:
Am 14.11.2014 15:32, schrieb Love Nystrom:

On 2014-11-14 00.41, Alex Ionescu wrote:
I would much rather see if (f != FALSE) instead of if ( f ).
Well, it's certainly a valid option, and C++ compilers seem to generate
[abbrev]
"if (f != FALSE)" and "if (f)" are exactly 100% the same for the compiler. "if (f)" is nothing but a synonym for "if (f != 0)" and FALSE is 0.

Well... Actually not exactly the same.. ;)
"if (f != FALSE)" requires an explicit comparison with a second operand,
whereas "if ( f )" can be performed by comparing the value *with itself* using an OR instruction.
You'll see that a lot in the C string library (I think you know this), where it's used to check quickly
for the terminating NUL without having to compare with a second operand.

Best Regards
// Love

Whether it creates a CMP, or an OR or a TEST is all up to the compiler and it will be the same in both cases. If it was not the same, there is something ... well not neccessarily "wrong" but at least very strange with the compiler.


I expect some people will use the former.
Personally I much prefer the latter.
I think both have their pros and cons. So I don't really care.