Join the discussion

Write your take first — we'll ask for email only when you're ready to publish.

  • Hacker News
  • 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!
  • While I understand why C++ defines bool as an Integer, it might have been better if it wasn't. It's not a problem for me that in some modern languages, boolean cannot be mixed with numbers in an expression.
  • Or just use a damn language that doesn’t blur integers and booleans.

    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.

  • 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.
  • 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
  • They should have defined true as -1 (all bits set) instead, as in some other languages like Forth and BASIC.
  • 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.

Explore Birbla archives