Why is this an issue?
Trigraphs are denoted by a sequence of 2 question marks followed by a specified third character (e.g. ??- represents a '~' (tilde) character and
??) represents a ']'). They can cause accidental confusion with other uses of two question marks.
Noncompliant code example
static const char str[] = "(Date should be in the form ??-??-??)"; // Noncompliant. Evaluates to "(Date should be in the form ~~]"
Compliant solution
static const char str[] = "(Date should be in the form ?" "?-?" "?-?" ?)"; // adjacent string literals concatenated at compile time
static const char str2[] = "(Date should be in the form ?-?-?)"; // problem avoided by eliminating 2nd '?' in each sequence
static const char str3[] = "(Date should be in the form ? ?-? ?-? ?)"; // problem avoided by spacing '?'s out
Resources
Documentation
Standards
External coding guidelines
- MISRA C:2004, 4.2 - Trigraphs shall not be used
- MISRA C++:2008, 2-3-1 - Trigraphs shall not be used
- MISRA C:2012, 4.2 - Trigraphs shall not be used