C alternative tokens explained

C alternative tokens refer to a set of alternative spellings of common operators in the C programming language. They are implemented as a group of macro constants in the C standard library in the iso646.h header. The tokens were created by Bjarne Stroustrup for the pre-standard C++ language[1] and were added to the C standard in a 1995 amendment to the C90 standard via library to avoid the breakage of existing code.

The alternative tokens allow programmers to use C language bitwise and logical operators which could otherwise be hard to type on some international and non-QWERTY keyboards. The name of the header file they are implemented in refers to the ISO/IEC 646 standard, a 7-bit character set with a number of regional variations, some of which have accented characters in place of the punctuation marks used by C operators.

The macros

The iso646.h header defines the following 11 macros as stated below:[2]

Macro Defined as
and &&
and_eq &=
bitand &
bitor <nowiki>|</nowiki>|-| compl || ~|-| not || <nowiki>!</nowiki>
not_eq <nowiki>!=</nowiki>
or <nowiki>||</nowiki>
or_eq <nowiki>|</nowiki>=|-| xor || ^|-| xor_eq || ^=|}

C++

The above-mentioned identifiers are operator keywords in the ISO C++ programming language and do not require the inclusion of a header file.[3] For consistency, the C++98 standard provided both &lt;iso646.h&gt; and a corresponding &lt;ciso646&gt;. However they both had no effect, being empty.[4] [5] Some compilers, such as Microsoft Visual C++ have, at least in the past, required the header to be included in order to use these identifiers unless a compiler flag is set.[6] [7] The header &lt;ciso646&gt; was deprecated in C++17, and removed in C++20,[8] while &lt;iso646.h&gt; was retained for compatibility with C.[9]

See also

  • Digraphs and trigraphs in C

External links

Notes and References

  1. Web site: CppCon 2017: Panel "Grill the Committee" . . https://ghostarchive.org/varchive/youtube/20211212/JYG5LFHkUuE. 2021-12-12 . live.
  2. Web site: Rationale for International Standard - Programming Languages - C . 5.10 . April 2003 . 2010-10-17 . live . https://web.archive.org/web/20160606072228/http://www.open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf . 2016-06-06.
  3. Book: Design and Evolution of C++ . Bjarne . Stroustrup . Bjarne Stroustrup . . 1st . 1994-03-29 . 0-201-54330-3.
  4. Book: Lischner, Ray . 0-596-00298-X . C++ in a Nutshell . 384 . . 2003 .
  5. Book: Peter. Van Weert. Marc. Gregoire. 2019. C++17 Standard Library Quick Reference. Apress. 9781484249239. 277.
  6. Book: Paul. Deitel. Harvey M.. Deitel. C++11 for Programmers. 2013. 9780133439878. Pearson Education. 928.
  7. Web site: 2021-11-23. Logical AND Operator: &&. live. 2021-12-27. Microsoft Docs. https://web.archive.org/web/20211228013621/https://docs.microsoft.com/en-us/cpp/cpp/logical-and-operator-amp-amp?view=msvc-170 . 2021-12-28 .
  8. Web site: . 2021-12-07. Tyler. Whitney. Microsoft Learn.
  9. Thomas. Köppe. 2021-06-11. ISO/IEC JTC1 SC22 WG21. Clarifying the status of the "C headers". C++ Standards Committee Papers. live. 2024-01-11. https://web.archive.org/web/20240111125009/https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2340r1.html.