加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

每个使用冒号(“:”)在C

发布时间:2020-12-16 05:48:43 所属栏目:百科 来源:网络整理
导读:我很好奇一个冒号(“:”字符)在C程序中是一个有效的句法元素(在字符串/字符文字,注释等之外). 我尝试搜索C99规范,但“:”匹配每一个页面,“冒号”没有找到每一个用法.同样的,通过玩具C parsers(我明白lex / yacc aren’t capable的解析C),我似乎只是找到部
我很好奇一个冒号(“:”字符)在C程序中是一个有效的句法元素(在字符串/字符文字,注释等之外).

我尝试搜索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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读