C ++ 1z why not remove digraphs along with trigraphs?

C ++ 1z will remove trigraphs. IBM strongly opposed this ( here and here ), so there seems to be arguments for both sides of the delete / delete.

But since it was decided to remove the trigraphs, why leave the digraphs? I see no reason to keep digraphs outside of reasons to keep the trigraphs (which apparently didn't have enough weight to hold them).

+17
c ++ standards c ++ 1z digraphs
Dec 22 '14 at 11:22
source share
1 answer

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.

+26
Jan 20 '15 at 19:03
source share



All Articles