Setting extra bits in a bool makes it true and false at the same time

In C++ the bit representation (and even the size) of a bool is implementation defined; generally it’s implemented as a char-sized type taking 1 or 0 as possible values. If you set its value to anything different from the allowed ones (in this specific case by aliasing a bool through a char and modifying its … Read more

Why use !! when converting int to bool?

The problems with the “!!” idiom are that it’s terse, hard to see, easy to mistake for a typo, easy to drop one of the “!’s”, and so forth. I put it in the “look how cute we can be with C/C++” category. Just write bool isNonZero = (integerValue != 0); … be clear.

tech