是双引号(“)是预处理式的或未终止的字符串字面的?

发布于 2025-01-20 14:02:06 字数 558 浏览 1 评论 0原文

双引号 (") 是预处理标记还是未终止的字符串文字?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离去的眼神 2025-01-27 14:02:06

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文