5

I'm translating a C++ function I wrote some time ago into python when I noticed that my C++ code contains the following lines:

  if(MIsScaledOut()) {
    if(DataType()==UnknownDataType or DataType()==h)
      Descriptor = Descriptor + DataTypeString() + "OverM";

There's an or in there! This was probably because I previously translated from python, and forgot to switch to ||.

This code compiles in various OSes, with various compilers, and I've never seen a problem with it. Is this standard, or have I just gotten lucky so far, and this is something I should worry about?

Mike
  • 19,114
  • 12
  • 59
  • 91
  • 3
    It's really sad that everyone is using `||` and `&&` instead of `and` and `or`. – Elazar Nov 05 '14 at 21:13
  • 2
    @Elazar: What's sad is that perfectly cromulent identifiers, which appear often in logic, have been made unavailable in all scopes. – Ben Voigt Nov 05 '14 at 21:24
  • 3
    It's always fun to embiggen a language. [Sorry; I just had to...] – Mike Nov 05 '14 at 21:26
  • It should have been opt-in through standadized compiler directive. Just like the digrams/trigrams (together with their template problems) – Elazar Nov 05 '14 at 22:16
  • This is valid, although [there are some details](http://stackoverflow.com/a/18186331/1708801), in C you need to include `iso646.h` and Visual Studio in not compliant in C++ and they don't plan on fixing it. – Shafik Yaghmour Nov 06 '14 at 03:59

1 Answers1

8

After remembering the right word to google, I now see that it is listed as a C++ keyword, along with various similar keywords like and that I'd never seen (noticed?) before in C++. The reason these exist is because there are encodings that don't have some of the required punctuation characters used by the traditional operator spellings: {, }, [, ], #, \, ^, |, ~.

As @mafso points out, the alternative "spelled out" versions can be used in C by including the <iso646.h> header, which defines them as macros.

The question of which this has been marked duplicate also points out the existence of digraphs and trigraphs, which can be used to substitute for the missing characters. (That question also says "everybody knows about" them. Obviously, I did not...)

Community
  • 1
  • 1
Mike
  • 19,114
  • 12
  • 59
  • 91
  • 1
    Remember to click on the checkmark to close the question. – Thomas Matthews Nov 05 '14 at 21:13
  • As this is also tagged with C, it could be noted, that they aren't keywords there (e.g. writing `int and = 42;` is legal), but are provided as macros if `` is included (cf C11 (n1570) 7.9). – mafso Nov 05 '14 at 21:19
  • @ThomasMatthews I have to wait two days to accept my own answer. :\ – Mike Nov 05 '14 at 21:21
  • @mafso True. It's mentioned in the second link in this answer, but it doesn't hurt to be explicit. Thanks! – Mike Nov 05 '14 at 21:22