I've just read this nice piece from Reddit.
They mention and
and or
being "Alternative Tokens" to &&
and ||
I was really unaware of these until now. Of course, everybody knows about the di-graphs and tri-graphs, but and
and or
? Since when? Is this a recent addition to the standard?
I've just checked it with Visual C++ 2008 and it doesn't seem to recognize these as anything other than a syntax error. What's going on?
They've been there since C++ 98.
C Tokens are of 6 types, and they are classified as: Identifiers, Keywords, Constants, Operators, Special Characters and Strings.
There are 6 types of C tokens : identifiers, keywords, constants, operators, string literals and other separators.
From the first ISO C++ standard C++98
, this is described in 2.5/ Alternative tokens [lex.digraph]
:
Table 2 - Alternative tokens alternative primary | alternative primary | alternative primary --------------------+---------------------+-------------------- <% { | and && | and_eq &= %> } | bitor | | or_eq |= <: [ | or || | xor_eq ^= :> ] | xor ^ | not ! %: # | compl ~ | not_eq != %:%: ## | bitand & |
So it's been around since the earliest days of the C++ standardisation process. The reason so few people are aware of it is likely because the main use case was for people operating in environments where the full character set wasn't necessarily available. For example (and this is stretching my memory), the baseline EBCDIC character set on the IBM mainframes did not have the square bracket characters [
and ]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With