...
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 | ||||
---|---|---|---|---|
| ||||
// whatWhat is the value of a now??/ a++; |
...
The following compliant solution eliminates the accidental introduction of the trigraph by separating the question marks.:
Code Block | ||||
---|---|---|---|---|
| ||||
// whatWhat is the value of a now? ?/ a++; |
...
This noncompliant code example includes the trigraph sequence ??!
, which is replaced by the character |
.:
Code Block | ||||
---|---|---|---|---|
| ||||
size_t i = /* some initial value */; if (i > 9000) { if (puts("Over 9000!??!") == EOF) { /* Handle Errorerror */ } } |
This example prints Over 9000!|
if a C-compliant compiler is used.
...
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 Errorerror */ } } |
This code prints Over 9000!??!
, as intended.
...
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 |
...
CERT C++ Secure Coding Standard | PRE07-CPP. Avoid using repeated question marks |
MISRA - C:2012 | Rule 4.2 (advisory) |
Bibliography
[ISO/IEC 9899:2011] | Section 5.2.1.1, "Trigraph Sequences" |
...