gpt4 book ai didi

c - 在 C 中每次使用冒号 (":")

转载 作者:太空狗 更新时间:2023-10-29 16:43:13 25 4
gpt4 key购买 nike

我很好奇在 C 程序中冒号(“:”字符)是有效句法元素(在字符串/字 rune 字、注释等之外)的每个上下文。

我尝试搜索 C99 规范,但“:”与每个页面都匹配,而“冒号”并未找到所有用法。同样,通过查看玩具 C parsers (而且我理解 lex/yacc aren't capable 的解析 C)我似乎只找到部分结果。

这些是我所知道的使用冒号的场景:

  • 条件运算符
  • 位域
  • 标签

C 语言中是否还有使用冒号的其他语言功能?

最佳答案

C 标准 (N1570) 定义了二合字母:

6.4.6 Punctuators
....

3   In all aspects of the language, the six tokens

        <: :> <% %> %: %:%:

  behave, respectively, the same as the six tokens 79)

        [ ] { } # ##

except for their spelling.80)


79) These tokens are sometimes called ‘‘digraphs’’.

80) Thus [ and <: behave differently when ‘‘stringized’’ (see 6.10.3.2), but can otherwise be freely interchanged.

作为旁注,C++ 标准详细阐述了该术语:

The term “digraph” (token consisting of two characters) is not perfectly descriptive, since one of the alternative preprocessing-tokens is %:%: and of course several primary tokens contain two characters. Nonetheless, those alternative tokens that aren’t lexical keywords are colloquially known as “digraphs”.

根据 Digraphs and trigraphs :

In 1994 a normative amendment to the C standard, included in C99, supplied digraphs as more readable alternatives to five of the trigraphs. ....

Unlike trigraphs, digraphs are handled during tokenization, and any digraph must always represent a full token by itself, or compose the token %:%: replacing the preprocessor concatenation token ##. If a digraph sequence occurs inside another token, for example a quoted string, or a character constant, it will not be replaced.

关于c - 在 C 中每次使用冒号 (":"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37635535/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com