We all know about the historical curiosity that is digraphs and trigraphs, but with all the changes made to C++ in recent years I'm curious: are they valid C++14? How about C++17?
This meant that it was hard to write C code on machines that used these sets. To solve this problem, the C standard suggested the use of combinations of three characters to produce a single character called a trigraph. A trigraph is a sequence of three characters, the first two of which are question marks.
Through C++14, trigraphs are supported as in C. Visual C++ continues to support trigraph substitution, but it's disabled by default. For information on how to enable trigraph substitution, see /Zc:trigraphs (Trigraphs Substitution). The following table shows the nine trigraph sequences.
In computer programming, digraphs and trigraphs are sequences of two and three characters, respectively, that appear in source code and, according to a programming language specification, should be treated as if they were single characters. Why Digraphs and Trigraphs exist?
A trigraph is always treated as a single source character. The translation of trigraphs takes place in the first translation phase, before the recognition of escape characters in string literals and character constants. Only the nine trigraphs shown in the above table are recognized. All other character sequences are left untranslated.
Trigraphs are currently valid, but won't be for long!
Trigraphs were proposed for deprecation in C++0x, which was released as C++11. This was opposed by IBM, speaking on behalf of itself and other users of C++, and as a result trigraphs were retained in C++0x. Trigraphs were then proposed again for removal (not only deprecation) in C++17. This passed a committee vote, and trigraphs are expected to be removed from C++17 despite the opposition from IBM and others. Existing code that uses trigraphs can be supported by translating from the physical source files (parsing trigraphs) to the basic source character set that does not include trigraphs. [Wikipedia]
Digraphs, however, are sticking around for now.
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