Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are trigraphs still valid C++?

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?

like image 752
Lightness Races in Orbit Avatar asked Dec 28 '14 16:12

Lightness Races in Orbit


People also ask

Why do we use trigraphs in C?

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.

Are trigraphs supported in C++14?

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.

What are digraphs and trigraphs?

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?

How are trigraphs treated in a string?

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.


1 Answers

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.

like image 125
Lightness Races in Orbit Avatar answered Sep 17 '22 15:09

Lightness Races in Orbit