Are digraphs and trigraphs in use today? [closed] Are digraphs and trigraphs in use today? [closed] c c

Are digraphs and trigraphs in use today? [closed]


I don't know for sure, but you're most likely to find digraphs and trigraphs being used in IBM mainframe environments. The EBCDIC character set doesn't include some characters that are required for C.

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

Outside such environments, I suspect that trigraphs are more commonly used by mistake than deliberately, as in:

puts("What happened??!");

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

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

The replacements occur anywhere in source code, including comments and string literals.

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

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

Digraphs were introduced by the 1995 amendment to the 1990 ISO C standard.


There is a proposal pending for C++1z (the next standard after C++1y will be standardized into -hopefully- C++14) that aims to remove trigraphs from the Standard. They did a case study on an otherwise undisclosed large codebase:

Case study

The uses of trigraph-like constructs in one large codebase were examined. We discovered:

923 instances of an escaped ? in a string literal to avoid trigraph replacement: string pattern() const { return "foo-????\?-of-?????"; }

4 instances of trigraphs being used deliberately in test code: two in the test suite for a compiler, the other two in a test suite for boost's preprocessor library.

0 instances of trigraphs being deliberately used in production code. Trigraphs continue to pose a burden on users of C++.

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

If trigraphs are removed from the language entirely, an implementation that wishes to support them can continue to do so: its implementation-defined mapping from physical source file characters to the basic source character set can include trigraph translation (and can even avoid doing so within raw string literals). We do not need trigraphs in the standard for backwards compatibility.