14

Yes, this is valid C++ :

if (false or (true and not false)) ...

Among others such as bitand and xor. In C, they used to be macros, but now they are keywords ! You can even overload them ! Then why would someone ever teach or write something like :

if (false || (true && !(false))) ...

Why is nobody using them ?

fouronnes
  • 3,838
  • 23
  • 41
  • "In C, they used to be macros" No, they were never macros "in C", although some individual C programs may have defined such macros. Adn this isn't a real question, it's opinionated and argumentative -- see the FAQ. – Jim Balter Mar 12 '11 at 13:18
  • possible duplicate of [Is anybody using the named boolean operators?](http://stackoverflow.com/questions/1103313/is-anybody-using-the-named-boolean-operators) [Which C++ logical operators do you use: and, or, not and the ilk or C style operators? why?](http://stackoverflow.com/questions/1103313/is-anybody-using-the-named-boolean-operators) ; see also [C++ alternative tokens?](http://stackoverflow.com/questions/555505/c-alternative-tokens) [Is it possible to turn off support for “and” / “or” boolean operator usage in gcc?](http://stackoverflow.com/questions/1069352) – CB Bailey Mar 12 '11 at 13:23
  • 1
    @Jim Balter: But in C, they _are_ macros, defined in `iso646.h`. – Sebastian Mach Sep 09 '11 at 15:09
  • @phresnel I stand corrected. But then the claim that they used to be macros but are now keywords in *C* is false ... they are still macros in C. – Jim Balter Oct 08 '11 at 02:54
  • @Jim Balter: That's true, my comment was to both, you and the OP. Unfortunately one can't [at]ify multiple users. – Sebastian Mach Oct 11 '11 at 08:36
  • @phresnel I believe that the OP always gets notified. – Jim Balter Oct 14 '11 at 01:46
  • True. But now _you_ did possibly not know that I meant both :D – Sebastian Mach Oct 14 '11 at 08:02

4 Answers4

7

Because they don't allow mixed C/C++ code without including additional header files, are less known to programmers, and it's not immediately clear whether and is the short-circuit or bitwise version.

phihag
  • 278,196
  • 72
  • 453
  • 469
  • 3
    Yeah, between `&` and `&&` it is much easier to guess which one is a bitwise operator than between `and` and `bitand`. It is unfortunate though that `not_eq` is a relation, while `or_eq` is a compound assignment operator, which ironically is bitwise. – Marc van Leeuwen Jun 23 '14 at 03:56
2

Why nobody? Some use them. Others think that symbols are more readable than words.

Yakov Galka
  • 70,775
  • 16
  • 139
  • 220
2

Visual C++ does not support them.

fredoverflow
  • 256,549
  • 94
  • 388
  • 662
  • Microsoft Visual C++ requires to be included in order to use these identifiers, adding another useless dependency to something that should be in the base language. (or shouldn't, but shouldn't sit somewhere in the middle) – Tic Apr 25 '17 at 07:55
1

People just don't know about them(I didn't until now).

MoonBun
  • 4,322
  • 3
  • 37
  • 69