是双引号(“)是预处理式的或未终止的字符串字面的?
双引号 ("
) 是预处理标记还是未终止的字符串文字?
C11, 6.4 词法元素,语法,1:
preprocessing-token:
header-name
identifier
pp-number
character-constant
string-literal
punctuator
each non-white-space character that cannot be one of the above
C11, 6.4.5 字符串文字,语法,1:
string-literal:
encoding-prefix(opt) " s-char-sequence(opt) "
注意:GCC 认为它成为未终止的字符串文字:
#if 0
"
#endif
产生:
warning: missing terminating " character
Is double quote ("
) a preprocessing-token or an unterminated string literal?
C11, 6.4 Lexical elements, Syntax, 1:
preprocessing-token:
header-name
identifier
pp-number
character-constant
string-literal
punctuator
each non-white-space character that cannot be one of the above
C11, 6.4.5 String literals, Syntax, 1:
string-literal:
encoding-prefix(opt) " s-char-sequence(opt) "
Note: GCC considers it to be an unterminated string literal:
#if 0
"
#endif
produces:
warning: missing terminating " character
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
C 2018 6.4.1 3说,预处理令牌的一个类别是“单个非白色空间字符,这些字符与其他预处理代币类别不符合其他情况”,下一个句子说“如果
'
或“
字符匹配最后一个类别,行为不确定。”因此,如果出现一个孤立的“
出现(一个与其他未与另一个配对的与 s-char-sequence 之间的配对),则失败匹配字符串的词汇形式,并将其解析为与其他类别相匹配的单个非白色空间字符,并且该行为未通过标准来定义。 .2 3描述
#
include 带有“”
q-char-sequence的指令> new-line ”。 i> new-line ”。表格显示为“
”
Q-char- sequence“
”,然后是##
inclage
段落正在讨论的类型的指令。)C 2018 6.4.1 3 says one category of preprocessing tokens is “single non-white-space characters that do not lexically match the other preprocessing token categories”, and the next sentence says “If a
’
or a"
character matches the last category, the behavior is undefined.” Thus, if an isolated"
appears (one that is not paired with another"
with an s-char-sequence between them), it fails to match the lexical form of a string literal and is parsed as a single non-white-space character that does not match the other categories, and the behavior is not defined by the standard. This explains the GCC message.(I note that 6.10.2 3 describes
#
include
directives with “"
q-char-sequence"
new-line”. However, the earlier grammar in 6.10 1 describes the directives as “#
include
pp-tokens new-line”. My interpretation of this is that the directive is parsed as having preprocessor token(s), notably a string literal, and 6.10.2 3 says that if that string literal has the form shown as “"
q-char-sequence"
”, then it is a#
include
directive of the type that paragraph is discussing.)