2.2 Trigraph sequences

2.2.1 Do not use digraphs or trigraphs

Trigraphs are special three character sequences, beginning with two question marks and followed by one other character. They are translated into specific single characters, e.g. \ or ^. Digraphs are special two character sequences that are similarly translated. Be aware of trigraph and digraph character sequences and avoid them. It is possible to avoid such sequences arising accidentally by using spaces. In most modern environments there is no longer a need for trigraphs or digraphs, and their use will either result in hard to diagnose compiler errors or code that is difficult to maintain.

Trigraph Equivalent   Digraph Equivalent
??= #   %:%: ##
??( [   %: #
??< {   <: [
??) ]   <% {
??> }   :> ]
??/ \   %> }
??’ ˆ      
??! |      
??- ~      
#include <cstdint>
#include <iostream>
#include <vector>
   
void f1 ()
{
// @@- Non-Compliant: here the ??/??/?? becomes \\?? after trigraph translation -@@
//
std::cout << "Enter date ??/??/??";
}
                 
void f2 ()
{
// @@- Non-Compliant: here the <::std::pair becomes [:std::pair -@@
//
::std::vector<::std::pair > vector_of_pairs;
}

References

  • HIC++ v3.3 – 14.18

Click here for references