| Wiki Markup |
|---|
Two consecutive question marks signify the start of a trigraph sequence. |
| Wiki Markup |
|---|
According to the C99 Standard \[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\]: |
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="c5964e890ff4349d-ce3d7147-45c248bd-89e786a6-02c5fcdeba698cd52b1000e3"><ac:plain-text-body><![CDATA[
??(
[
??'
^
??>
}
]]></ac:plain-text-body></ac:structured-macro>
??/
\
??<
{
??-
~
...
The following compliant solution eliminates the accidental introduction of the trigraph by separating the ?'squestion marks.
| Code Block | ||
|---|---|---|
| ||
// what is the value of a now? ?/ a++; |
...
| Code Block | ||
|---|---|---|
| ||
size_t i; = /* assignmentsome ofinitial ivalue */; if (i > 9000) { if (puts("Over 9000!??!") == EOF) { /* Handle Error */ } } |
This example prints Over 9000!| if a C99-compliant compiler is used.
Compliant Solution
The This compliant solution uses string concatenation to concatenate the two question marks; otherwise they are interpreted as beginning a trigraph sequence.
| Code Block | ||
|---|---|---|
| ||
size_t i = /* some initial value */;
/* assignment of i */
if (i > 9000) {
if (puts("Over 9000!?""?!") == EOF) {
/* Handle Error */
}
}
|
...
Inadvertent trigraphs can result in unexpected behavior. 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 (see MSC00-C. Compile cleanly at high warning levels).
...