...
All occurrences in a source file of the following sequences of three characters (that is, trigraph sequences) are replaced with the corresponding single character.
??=
#
??)
]
??!
|
??(
[
??'
^
??>
}
??/
\
??<
{
??-
~
Noncompliant Code Example
In this noncompliant code example, a++
is not executed because the trigraph sequence ??/
is replaced by \
, logically putting a++
on the same line as the comment:
...
Code Block | ||||
---|---|---|---|---|
| ||||
size_t i = /* someSome initial value */; if (i > 9000) { if (puts("Over 9000!??!") == EOF) { /* Handle error */ } } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
size_t i = /* someSome initial value */; /* assignmentAssignment 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.)
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
PRE07-C | lowLow | unlikelyUnlikely | mediumMedium | P2 | L3 |
Automated Detection
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
| dtrigraf | Fully implemented | |||||||
GCC |
| Can detect violation of this recommendation when the | |||||||
| 81 S | Fully implemented | |||||||
PRQA QA-C |
| 3601 | Partially implemented |
...