Re:Perlsecret – Perl secret operators and constants
by lkbm on Monday January 12, 2026 @08:46PM
(#46596479)
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.
Re:Perlsecret – Perl secret operators and constants
by defrost on Monday January 12, 2026 @08:52PM
(#46596524)
Err, C bools have two interpreted values, TRUE, and FALSE.
Confusingly (to some) they are integers and while 0 represents FALSE, any non 0 value represents TRUE.
It's pedantic, apologies, but that is why the GP refers to "convert to 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.