[lex.ccon] 中 c-char 的定义可能存在矛盾
Possible contradiction in the definition of c-char in [lex.ccon]
[lex.ccon] 包含 c-char 的以下定义:
c-char:
any member of the source character
set
except the
single-quote ’
, backslash \
, or new-line character
escape-sequence
universal-character-name
鉴于new-line character in C
is the escape-sequence \n
,上面的定义是不是自相矛盾?
PS:请注意,C++ 标准并未真正定义什么是换行符。
不,当定义说 "new-line character" 时,它意味着 actual new-line,而不是特殊的 two-character 序列(反斜杠和 n
) 在特殊情况下(在常量字符串或字符文字中)可以被编译器解释为 new-line。
C++ 标准确实指出 translation phase 1, the source file is decomposed into preprocessing tokens (A character-literal is a preprocessing token) and sequences of white-space characters (including comments) in translation phase 3, and each escape sequence (\n
is a escape sequence) is converted to the corresponding member of the execution character set in translation phase 5 中的 end-of-line 个指标引入了 new-line 个字符。
所以明确定义了当组成character-literal时,字符序列\n
不会变成new-line字符,和 end-of-line 指示符(以及翻译阶段 1 的所有细节,是 implementation-defined,但普遍认为 end-of-line 指示符在 Unix 上是 LF 而 Unix-like 系统,Windows) 上的 CR+LF 已经变成了 new-line 字符。
[lex.ccon] 包含 c-char 的以下定义:
c-char:
any member of the source character set
except the single-quote’
, backslash\
, or new-line character
escape-sequence
universal-character-name
鉴于new-line character in C
is the escape-sequence \n
,上面的定义是不是自相矛盾?
PS:请注意,C++ 标准并未真正定义什么是换行符。
不,当定义说 "new-line character" 时,它意味着 actual new-line,而不是特殊的 two-character 序列(反斜杠和 n
) 在特殊情况下(在常量字符串或字符文字中)可以被编译器解释为 new-line。
C++ 标准确实指出 translation phase 1, the source file is decomposed into preprocessing tokens (A character-literal is a preprocessing token) and sequences of white-space characters (including comments) in translation phase 3, and each escape sequence (\n
is a escape sequence) is converted to the corresponding member of the execution character set in translation phase 5 中的 end-of-line 个指标引入了 new-line 个字符。
所以明确定义了当组成character-literal时,字符序列\n
不会变成new-line字符,和 end-of-line 指示符(以及翻译阶段 1 的所有细节,是 implementation-defined,但普遍认为 end-of-line 指示符在 Unix 上是 LF 而 Unix-like 系统,Windows) 上的 CR+LF 已经变成了 new-line 字符。