3 ms·
That's clever, but I am not a fan: Booleans are implementation dependent; making the assumption that Boolean 'true' evaluates to 1, or even a number greater tha
by kmoser 3y ago
That's clever, but I am not a fan: Booleans are implementation dependent; making the assumption that Boolean 'true' evaluates to 1, or even a number greater than what Boolean 'false' evaluates to, is not a good idea, even if it happens to be correct most of the time. Even if it is defined that way in the language specs, it might not be defined that way in a future version of that language or certainly not necessarily in other, simlar languages.
Now, if you're exploiting that quirk for performance purposes, that's another story. But then the code should be labeled as such.
- deleted 3y ago[deleted]
- AgentME 3y agoThe comparison operators are specifically defined in the C standard to output 1 if true and 0 if false.
- viraptor 3y agoI was curious about the details. 6.5.8 in https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf Also 7.18 makes the bool macros explicitly 1 and 0.