允许```被转义的理由是什么? [英] What is the rationale in allowing `?` to be escaped?
问题描述
从 2.13.2 / 3
双引号
code>和问号
?
可以表示为
本身或转义序列\
和\?
[...]。
The double quote
"
and the question mark?
, can be represented as themselves or by the escape sequences\"
and\?
[...].
简单地说,如下:
char x = '\?'; //or '\"'
char y = '?'; //or '"'
$ b b
表示相同的字符。为什么要处理这两个(特别是?
)不同于其他字符?
推荐答案
\
提供单引号字符文字和双引号字符串文字之间的一致性(它们被定义为使用相同的转义序列,结果 \'
和 \
可以在两者中使用)。我稍微猜一猜,但我估计委员会只是想在每个中定义不同的转义序列太麻烦了,没有好处,可以说是轻微的损害。
\"
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.
这篇关于允许```被转义的理由是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!