ccharstrigraphs

Curious trigraph sequence thing about ansi C


What was is it the original reason to use trigraph sequence of some chars to become other chars in ansi C like:

??=define arraycheck(a, b) a??(b??) ??!??! b??(a??)

becomes

#define arraycheck(a, b) a[b] || b[a]

Solution

  • Short answer: keyboards/character encodings that didn't include such graphs.

    From wikipedia:

    The basic character set of the C programming language is a superset of the ASCII character set that includes nine characters which lie outside the ISO 646 invariant character set. This can pose a problem for writing source code when the keyboard being used does not support any of these nine characters. The ANSI C committee invented trigraphs as a way of entering source code using keyboards that support any version of the ISO 646 character set.

    http://en.wikipedia.org/wiki/Digraphs_and_trigraphs