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

C 11标准中的哪一节规定了原始数据类型大小之间的相对排序?

发布时间:2020-12-16 10:14:49 所属栏目:百科 来源:网络整理
导读:我试图找出C标准是否指定了各种类型的大小之间的关系.例如,https://stackoverflow.com/a/589599/1175080的答案似乎声称: sizeof(short int) = sizeof(int) = sizeof(long int) https://stackoverflow.com/a/589684/1175080的另一个答案有类似的说法: sizeo
我试图找出C标准是否指定了各种类型的大小之间的关系.例如,https://stackoverflow.com/a/589599/1175080的答案似乎声称:

sizeof(short int) <= sizeof(int) <= sizeof(long int)

https://stackoverflow.com/a/589684/1175080的另一个答案有类似的说法:

sizeof(int) <= sizeof(long)

我正在经历n3337.pdf(我相信C 11标准的良好代理)但我找不到保证这些不等式的特定语言.

在n1256(C99)中,我可以在5.2.4.2.1尺寸中找到特定的语言
整数类型清楚地说明每种类型的最小值和最大值,间接确定大小之间的相对排序.

这些不等式是否在C标准中类似地定义,还是直接从C继承?标准中的语言在哪里?

解决方法

在n3337中,该部分是 3.9.1,[basic.fundamental]/2,第二段(重点是我的):

There are five standard signed integer types : “signed char”,“short int”,“int”,“long int”,and “long long int”. In this list,each type provides at least as much storage as those preceding it in the list. There may also be implementation-defined extended signed integer types. The standard and extended signed integer types are collectively called signed integer types. Plain ints have the natural size suggested by the architecture of the execution environment44; the other signed integer types are provided to meet special needs.

请注意,C标准中的5.2.4.2/1仅定义了每个整数类型的最小范围,它不强制执行排序 – 我可以从-32767到32767使用int,从-2147483647到2147483647使用,并且仍然符合本节的要求.

但是6.2.5.8更加明确:

For any two integer types with the same signedness and different integer conversion rank (see 6.3.1.1),the range of values of the type with smaller integer conversion rank is a subrange of the values of the other type.

而6.3.1.1告诉你:

The rank of long long int shall be greater than the rank of long int,which shall be greater than the rank of int,which shall be greater than the rank of short int,which shall be greater than the rank of signed char.

(编辑:李大同)

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

    推荐文章
      热点阅读