77 points · by aw1621107 · 1mo ago · 28 comments
bool Complement( bool x )
{
return ~x;
}
GCC gives a warning if compiling with -Wall: test.cpp:3:10: warning: ‘~’ on an expression of type bool [-Wbool-operation]
return ~x;
So, it's surprise that C++ does this, but ones who enable compiler warnings are not in trouble.Of course we can't have that now, because unsigned bool is baked into the C language standard, and even into processors (x86 SETcc instruction). While "char" being signed or not is still implementation-defined IIRC...
What expectations do you have of the value?
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p33...
The C language should be taken as a warning, not an ideal example!
If the actual encoding of the languages Boolean matters, then the design is WRONG.