C99 是否允许 UCHAR_MAX > UINT_MAX
6.3.1.1 状态
有符号整数类型的等级应大于任何精度较低的有符号整数类型的等级。
long long int 的等级应大于 long int 的等级,long int 的等级应大于 int 的等级,int 的等级应大于 Short int 的等级,short int 的等级应大于signed char 的等级。
那么,情况难道不是这样吗?
signed char has 32 bits (1 padding, 1 sign, 30 precision)
unsigned char has 32 bits (0 padding, 0 sign, 32 precision)
signed int has 32 bits (1 padding, 1 sign, 30 precision)
unsigned int has 32 bits (2 padding, 0 sign, 30 precision)
6.3.1.1 States
The rank of a signed integer type shall be greater than the rank of any signed integer type with less precision.
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.
So, could this not be the case
signed char has 32 bits (1 padding, 1 sign, 30 precision)
unsigned char has 32 bits (0 padding, 0 sign, 32 precision)
signed int has 32 bits (1 padding, 1 sign, 30 precision)
unsigned int has 32 bits (2 padding, 0 sign, 30 precision)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
刚刚找到了我自己的答案。这是不允许的,根据 6.2.5 (8)
对于任何两个具有相同符号性和不同整数转换等级的整数类型
(见6.3.1.1),整数转换等级较小的类型的取值范围是a
另一种类型的值的子范围。
Just found my own answer. This is not allowed, according to 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.
您对 char 变量的假设是错误的。在 limit.h 中,CHAR_BIT 为 8。您有 32。
在标准“5.2.4.2.1 整数类型的大小”中,将 CHAR_BIT 定义为 8。
You assumptions about char variables are wrong. In limits.h, CHAR_BIT is 8. You have 32.
In the standard '5.2.4.2.1 Sizes of integer types ' defines CHAR_BIT as 8.