4 ms·
C99: 6.5.3.3 p5: The result of the logical negation operator ! is 0 if the value of its operand compares unequal to 0, 1 if the value of its operand compares eq
by ben0x539 12y ago
C99: 6.5.3.3 p5: The result of the logical negation operator ! is 0 if the value of its operand compares unequal to 0, 1 if the value of its operand compares equal to 0. The result has type int. The expression !E is equivalent to (0==E).
C++11 (or a near enough draft): 5.3.1 p9: The operand of the logical negation operator ! is contextually converted to bool (Clause 4); its value is true if the converted operand is false and false otherwise. The type of the result is bool.
and 4.7 p4 on integral conversion: If the source type is bool, the value false is converted to zero and the value true is converted to one.
Both seem to suggest that when you apply !, you end up with something that is 0 or 1 when used as a number, and adding more ! won't get you out of that.
- akavel 12y agoThanks a lot! And still interested in earlier C/C++ standards, I'm much more likely to encounter them in the wild for long time.