Trigraphs are more problematic for an unfamiliar user than digraphs. This is because they are replaced in string literals and comments. Here are some examples ...
Example A:
std::string example = "What??!??!"; std::cout << example << std::endl;
What|| will be printed on the console. This is because the trigraph ??! translates to | .
Example B:
// Error ?!?!?!??!??/ std::cout << "There was an error!" << std::end;
Nothing will happen at all. This is due to the fact that ??/ translates to \ , which escapes the newline character and leads to the reading of the next line.
Example C:
// This makes no sense ?!?!!?!??!??/ std::string example = "Hello World"; std::cout << example << std::endl;
This will produce an error along the lines of use of undeclared identifier "example" for the same reasons as in Example B.
There are even more complex problems that trigraphs can cause, but you get the idea. It should be noted that many compilers do issue a warning when such translations are made; another reason to always treat warnings as errors. However, this is not required by the standard and therefore cannot be relied upon.
Digraphs are much less problematic than trigraphs, since they are not replaced inside another token (i.e. a string or a character literal), and there is no sequence that converts to \ , so there can be no escaping new lines in comments.
Conclusion
Besides the more difficult to read code, there are fewer problems caused by digraphs, and therefore the need to remove them is greatly reduced.
OMGtechy Jan 20 '15 at 19:03 2015-01-20 19:03
source share