logoalt Hacker News

The complement of true is true, except when it's false

48 points • by aw1621107 • last Sunday at 12:28 PM • 18 comments • view on HN

Comments

Panzerschrek • today at 1:46 PM

With such example:

  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.
nine_k • today at 3:18 PM

C++ is a true spiritual successor to Perl, in a way. It can express anything and everything, its syntax is arcane, as is its logic. Most of the time, of course, what you see is what you get, until the moment when what you see is what you don't get.

rep_lodsb • today at 8:52 AM

They should have defined true as -1 (all bits set) instead, as in some other languages like Forth and BASIC.

s-zeng • today at 11:28 AM

In any field of characteristic 2, every element is its own negative. So on the surface this makes sense, notwithstanding the unintuitive enum corner case behaviour

➕ show 1 reply
pwdisswordfishq • today at 11:57 AM

I wonder if [[=std::bitmask_type]] also enables compiler warnings that a switch statement is not exhaustive if it does not cover all possible flag combinations.

glownagger • today at 12:02 PM

I thought attributes were reserved for compiler-specific semantics like calling conventions. Here they're just being used as stropping for a language feature with syntactic significance!

➕ show 1 reply