Questions tagged [trigraphs]

Trigraphs in Standard C are three-character sequences starting with two question marks that are intended to help programmers using code sets without some of the characters used by C — {}[]#|^`\~ — which are not part of the invariant subset of ISO 646. Trigraphs were a part of C++ from C++98 through C++14, but were removed from C++17.

There are 9 trigraphs in Standard C:

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

Trigraphs are interpreted in translation phase 1, before the code is tokenized. This means that trigraphs can affect strings, character literals, and comments.

C++98 included trigraphs for compatibility with C90 and C99. Trigraphs were deprecated in C++14 and removed from C++7.

In 'Design and Evolution of C++', Stroustrup shows how Danish terminals might display a C++ program because Danish uses extra alphabetic characters in place of some ASCII characters:

int main(int argc, char* argvÆÅ)
æ
    if (argc < 1 øø *argvÆ1Å=='Ø0') return 0;
    printf("Hello, %søn",argvÆ1Å);
å

Encoded with trigraphs, that becomes:

int main(int argc, char* argv??(??))
??<
    if (argc < 1 ??!??! *argv??(1??)=='??/0') return 0;
    printf("Hello, %s??/n",argv??(1??));
??>

Written in full ASCII, the code is:

int main(int argc, char* argv[])
{
    if (argc < 1 || *argv[1]=='\0') return 0;
    printf("Hello, %s\n",argv[1]);
}

See also Wikipedia on Digraphs and Trigraphs.

33 questions
0
votes
1 answer

Strange behaviour of visual studio 2008 with escape sequence

Regarding C programming language, the descriptions of escape sequence does not resolve the output of following line in visual studio 2008. char * str = "??/abc"; printf( "%s", str ); it prints only "bc". Checking the memory pointed by str, we can…
Raj
  • 3
  • 1
0
votes
1 answer

(Di|Tri)graphs in C++11

After reading up on digraphs and trigraphs I went on and tested a simple program: #include int main() { int a = 0; //??/ ++a; printf("%d",a); return 0; } and by reflex I did g++ -std=c++11 test.c and to my surprise no…
user1233963
  • 1,450
  • 15
  • 41
0
votes
2 answers

how can I work with digraphs and trigrpahs in bloodshed/DevC++ compiler

In compiler trigraphs and digraphs are not replacing by the corresponding single characters. Rather it's giving a warning something like this, 12:26 G:\BIN\cLang\macro2.cpp [Warning] trigraph ??= ignored, use -trigraphs to enable I want to know…
amin__
  • 1,018
  • 3
  • 15
  • 22
1 2
3