Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
vzaliva
on Jan 5, 2024
|
parent
|
context
|
favorite
| on:
Dennis Ritchie on the priorities of && || vs. == e...
"true is a #define for 1" is bad idea. Because when `x` is, say, `2` then `if x` is not the same as `if x==true`.
BenjiWiebe
on Jan 6, 2024
[–]
That's just the way C is. If you want to check "truthiness" (as much as you can in C), just do 'if x'.
trealira
on Jan 6, 2024
|
parent
[–]
Something nice in C is that "if (x)" is always equivalent to "if (x != 0)". NULL is a macro for 0, and so is false. Boolean expressions evaluate to 0 if they don't hold. This isn't true in C++, though.
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: