C trigraph

C trigraph

In the C family of programming languages, a trigraph is a sequence of three characters, the first two of which are both question marks, that represents a single character.

The reason for their existence is that the basic character set of C (a subset of the ASCII character set) 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.

Trigraphs might also be used for some EBCDIC code pages that lack characters such as { and }.

Trigraphs are not commonly encountered outside compiler test suites ["The New C Standard: An Economic and Cultural Commentary" by Derek M. Jones, sentence 117] . Some compilers support an option to turn recognition of trigraphs off, or disable trigraphs by default and require an option to turn them on. Some can issue warnings when they encounter trigraphs in source files. Borland supplied a separate program, the trigraph preprocessor, to be used only when trigraph processing is desired (the rationale was to maximise speed of compilation).

Trigraph sequences

The C preprocessor replaces all occurrences of the following nine trigraph sequences by their single-character equivalents before any other processing.

Note that ??? is not a trigraph sequence.

Note also that the problematic characters are nevertheless required to exist within the implementation,in both the source and execution character sets.

The ??/ trigraph can be used to introduce an escaped newline for line splicing; this must be taken into account for correct and efficient handling of trigraphs within the preprocessor. It can also cause surprises, particularly within comments. For example:

// Will the next line be executed????????????????/ a++;

which is a single logical comment line, (used in C++ and C99), and

/??/ * A comment *??/ /

which is a correctly formed block comment.

Example

An example of a C program that uses all the defined trigraphs:??=include /* # */

int main(void)??< /* { */ char n??(5??); /* [ and ] */

n??(4??) = '0' - (??-0 ??' 1 ??! 2); /* ~, ^ and | */ printf("%c??/n", n??(4??)); /* , [ and ] */ return 0;??> /* } */

Disambiguation

A programmer may want to place two question marks together yet not have the compiler treat them as introducing a trigraph. The C grammar does not permit two subsequent ? tokens, so the only places in a C file where two question marks in a row may be used are in multi-character constants, string literals, and comments. To safely place two consecutive question marks within a string literal, the programmer can use string concatenation "...?""?..." or an escape sequence "...??...".

Alternatives

In 1994 a normative amendment to the C standard, included in C99, supplied so-called "digraphs" as more readable alternatives to six of the trigraphs. They are:

Unlike trigraphs, digraphs are handled during tokenization, and it must always represent a full token by itself. If a digraph sequence occurs inside another token, for example a quoted string, or a character constant, it will not be replaced.

References


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать реферат

Look at other dictionaries:

  • Trigraph — Tri graph, n. [Pref. tri + graph.] Three letters united in pronunciation so as to have but one sound, or to form but one syllable, as ieu in adieu; a triphthong. [1913 Webster] …   The Collaborative International Dictionary of English

  • trigraph — [trī′graf΄] n. [ TRI + GRAPH] a group of three letters representing one sound (Ex.: pph in Sappho) …   English World dictionary

  • Trigraph (orthography) — A trigraph (from the Greek: τρεῖς, treîs, three and γράφω, gráphō, write ) is a group of three letters used to represent a single sound or a combination of sounds that does not correspond to the written letters combined. For example, in the word… …   Wikipedia

  • Trigraph — Ein Trigraph ist eine Folge von drei Symbolen, zum Beispiel Buchstaben oder Zahlen. Inhaltsverzeichnis 1 Sprachwissenschaft 2 Programmiersprache C 3 Einzelnachweise 4 Weblinks …   Deutsch Wikipedia

  • Trigraph — A trigraph (from the Greek words tria = three and grapho = write) is a group of three symbols, most commonly letters.Trigraphs are used in several fields, and for several purposes. Among them are* In computing: ** A C trigraph, a character… …   Wikipedia

  • Trigraph (Linguistik) — Digraph bezeichnet in der Graphematik zwei Buchstaben, die für eine Lautung stehen. Für mehr als zwei Buchstaben verwendet man Trigraph, Tetragraph und so fort. Inhaltsverzeichnis 1 Begriffsbestimmung 2 Trigraph, Tetragraph… 3 Verwendung in… …   Deutsch Wikipedia

  • trigraph — noun Date: circa 1836 1. three letters spelling a single consonant, vowel, or diphthong < eau of beau is a trigraph > 2. a cluster of three successive letters < the, ion, and ing are high frequency trigraphs > • trigraphic adjective …   New Collegiate Dictionary

  • trigraph — n. (also trigram) 1 a group of three letters representing one sound. 2 a figure of three lines. * * * trigraph (ˈtraɪgrɑːf, æ ) [f. Gr. τρι tri + γραϕή writing, drawing.] A combination of three letters denoting a simple sound, as eau in F. beau,… …   Useful english dictionary

  • trigraph — trigraphic /truy graf ik/, adj. /truy graf, grahf/, n. a group of three letters representing a single speech sound, as eau in beau. [1830 40; TRI + GRAPH] * * * …   Universalium

  • trigraph — noun A group of three letters used to represent a single sound or a combination of sounds that does not correspond to the written letters combined. See Also: triphthong, ligature …   Wiktionary

  • trigraph — [ trʌɪgrα:f] noun a group of three letters representing one sound, for example German sch …   English new terms dictionary

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”