C99 是否允许 UCHAR_MAX > UINT_MAX

发布于 2024-09-06 05:16:31 字数 476 浏览 1 评论 0原文

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

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

发布评论

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

评论(2

韵柒 2024-09-13 05:16:31

刚刚找到了我自己的答案。这是不允许的,根据 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.

倾听心声的旋律 2024-09-13 05:16:31

您对 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.

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