A Boolean value represents a condition as false or true. In C, bool comes from stdbool.h; its values are false and true, corresponding technically to 0 and 1. section 3.1 section 5.7.4
Use a Boolean directly
Given bool b = ...;, write if (b) { ... } rather than if ((b != false) == true) { ... }. A condition should use an existing truth value directly. section 3.1
Keep these rules in view:
- Treat 0 as logical false and every nonzero numerical value as logical true. section 3.1
- Use bool when assignment should reduce a stored value to false or true; Boolean assignment follows a special rule rather than ordinary modulus behavior. section 5.7.4
- Do not compare a truth value to 0, false, or true; use the value itself as the condition. section 3.1
bool b = ...;
...
if (b) {
...
}
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":2,\"ch\":3},{\"line\":2,\"ch\":5}]]"}
!@%STYLE%@!
Inspect the compact form of a Boolean condition and compare it with the redundant form. section 3.1










