...
All occurrences in a source file of the following sequences of three characters (that is, trigraph sequences) are replaced with the corresponding single character.
??=
#
??)
]
??!
|
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0998e90b74411d22-401ba658-447648f4-baa29e66-53b828087c2ec841c2a4b043"><ac:plain-text-body><![CDATA[
??(
[
??'
^
??>
}
]]></ac:plain-text-body></ac:structured-macro>
??/
\
??<
{
??-
~
...
In this non-compliant code example, a++
is not executed, as because the trigraph sequence ??/
is replaced by \,
logically putting a++
on the same line as the comment.
...
Non-Compliant Code Example
This non-compliant code has example includes the trigraph sequence of ??!
included, which is replaced by the character |
.
Code Block | ||
---|---|---|
| ||
size_t i; /* assignment of i */ if (i > 9000) { puts("Over 9000!??!"); } |
The above code This example prints out Over 9000!|
if a C99-compliant compiler is used.
...
The compliant solution uses string concatenation to place concatenate the two question marks together, because they will be ; otherwise they are interpreted as beginning a trigraph sequence otherwise.
Code Block | ||
---|---|---|
| ||
size_t i; /* assignment of i */ if (i > 9000) { puts("Over 9000!?""?!"); } |
The above code will print out prints Over 9000!??!
, as intended.
...
Some compilers provide options to warn when trigraphs are encountered, or to disable trigraph expansion. Use the warning options and ensure your code compiles cleanly (MSC00-A. Compile cleanly at high warning levels)
...