Are digraphs and trigraphs used today?

Given that there were once reasons to use digraphs and trigraphs in C and C ++, does anyone put them in the code that is being written now? Is there any significant amount of legacy maintenance code that contains them?

(Note: here, “digraph” does not mean “directional graph.” Both digraph and trigraph have several meanings, but the intended use here is sequences like ??= or <: to be present in characters like # and [ )

+37
c ++ c digraphs
Sep 16 2018-11-11T00:
source share
5 answers

There is a proposal awaiting confirmation for C ++ 1z (the next standard after C ++ 1y will be standardized in -hopefully-C ++ 14), the purpose of which is to remove trigraphs from the Standard. They conducted a case study on an undisclosed large code base:

Case study

The use of trigar-like constructions in one large code base has been considered. We discovered:

923 copies of the screen? in string literature, to avoid the replacement trif:: string pattern () const {return "foo - ???? \? - of - ?????"; }

4 instances of trigrams are used deliberately in the test code: two in the test suite for the compiler, two others in the test suite to enhance the preprocessor library.

0 instances of trigrams that are intentionally used in the production code. Trigraphs still create a burden for C ++ users.

The proposal notes (bold emphasis from the original proposal):

If the trigraphs are completely removed from the language, the implementation that wants to support them can continue to do this: its mapping, determined by the implementation, from the physical characters of the source file to the main character set of the source, can include trifid translation (and can even avoid this within string literals). We do not need trigraphs in the standard for backward compatibility .

+13
Jul 16 '14 at 13:02
source share

I don’t know for sure, but you will most likely find digraphs and trigraphs used in IBM mainframe environments. The EBCDIC does not contain some of the characters that are required for C.

Another excuse for digraphs and trigraphs, 7-bit ASCII-ish character sets that replace some punctuation characters with accented letters, is probably less relevant today.

Outside of such environments, I suspect that trigraphs are more often used by mistake than intentionally, as in:

 puts("What happened??!"); 

For reference, trigraphs were introduced in the 1989 ANSI C standard (which essentially became the ISO ISO 1990 standard). It:

 ??= # ??) ] ??! | ??( [ ??' ^ ??> } ??/ \ ??< { ??- ~ 

Substitutions occur anywhere in the source code, including comments and string literals.

Digraphs are alternative spellings of certain tokens and do not affect comments or literals:

 <: [ :> ] <% { %> } %: # %:%: ## 

The diffractors were amended in 1995 to the 1990 ISO C standard.

+24
Sep 16 2018-11-11T00:
source share
+8
Jun 24 '14 at 15:43
source share

The use of tri and di-graph is not recorded on this day, it exists only in very old code that was created in a very limited environment. Any code that contains trigraphs, if you try to compile them in a modern compiler such as VS, it usually does not compile unless you specify the linker option. I know that for Visual Studio this option is "/ Zc: trigraphs"

Why do they exist, because the C ++ committee never releases changes that would “break” legacy code. Better or worse. There is a joke that their removal was proposed and supported, and it was stopped by a lone IBM representative.

+5
Sep 17 2018-11-11T00:
source share

I know this is an old question, but legal use is possible these days: touch screens without a real keyboard. For example, a typical US keyboard layout is not always available in full form if you are encoding using a tablet or something like that, admittedly, is, we hope, rare because of how cumbersome it is (three clicks for the assignment operator) I personally do not use them if possible, but they are useful in the absence of the actual tokens that they should represent.

Again, I really hope that people avoid this whenever possible, but this is one reason to learn and use them.

+3
Feb 16 '13 at 0:55
source share



All Articles