c++cdigraphstrigraphs

Are digraphs and trigraphs in use today?


Given that there were once reasons to use digraphs and trigraphs in C and C++, does anyone put them in code being written today? Is there any substantial amount of legacy code still under maintenance that contains them?

(Note: Here, "digraph" does not mean "directed graph." Both digraph and trigraph have multiple meanings, but the intended use here are sequences like ??= or <: to stand in for characters like # and [)


Solution

  • 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.