This is due to C legacy operator mechanization (also recalling that ~
is bitwise complement). Integral operands to ~
are promoted to int before doing the operation, then converted back to bool
. So effectively what you're getting is (using unsigned 32 bit representation) false
-> 0
-> 0xFFFFFFFF
-> true
. Then true
-> 1
-> 0xFFFFFFFE
-> 1
-> true
.
You're looking for the !
operator to invert a boolean value.