| ▲ | johnisgood 4 hours ago | |||||||
Keep in mind that applying the logical NOT operator twice (using `!!`) converts any integer expression into a strict boolean. Any non-zero value becomes `1`, and zero remains `0`. This is commonly used for boolean normalization when the original expression yields a bitmask or arbitrary integer. While the same result can be written as `(x != 0)`, the `!!x` idiom is concise, widely used in low-level C code, guarantees a result of exactly `0` or `1`, and works well in macros and constant expressions. | ||||||||
| ▲ | lkbm 3 hours ago | parent [-] | |||||||
Fair, I forgot that C bools are just 0 and 1. That's where I first learned the !! trick, but it's been many a year. | ||||||||
| ||||||||