Search code examples
c++language-designlanguage-lawyer

What is the rationale in allowing `?` to be escaped?


From 2.13.2/3

The double quote " and the question mark ?, can be represented as themselves or by the escape sequences \" and \? [...].

Simply put, the following:

char x = '\?'; //or '\"'
char y = '?';  //or '"'

represent the same character. Why treat these two (especially ?) differently than other characters?


Solution

  • \" gives consistency between single-quoted character literals and double-quoted string literals (they're defined to use the same escape sequences, as a result \' and \" can be used in both). I'm slightly guessing, but I reckon the committee just figured it was too much bother to define different escape sequences in each, for no benefit and arguably a slight detriment.

    \? is for avoiding trigraphs: ??= is a trigraph, ?\?= isn't.