Single UNIX 或 POSIX 中 sizeof(int) 的保证
Single UNIX 或 POSIX 中 int
的大小保证是多少?这确实是一个常见问题解答,但我找不到答案......
What are the size guarantees on int
in Single UNIX or POSIX? This sure is a FAQ, but I can't find the answer...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有了icecrime的回答,并在我这边进一步搜索,我得到了一个完整的图片:
ANSI C和C99都要求INT_MAX至少为+32767(即2^15-1)。 POSIX 并不止于此。 Single Unix v1 具有相同的保证,而 Single Unix v2 规定最小可接受值为 2 147 483 647(即 2^31-1)。
With icecrime's answer, and a bit further searching on my side, I got a complete picture:
ANSI C and C99 both mandate that INT_MAX be at least +32767 (i.e. 2^15-1). POSIX doesn't go beyong that. Single Unix v1 has the same guarantee, while Single Unix v2 states that the minimum acceptable value is 2 147 483 647 (i.e. 2^31-1).
C99 标准按以下方式指定标头
的内容:int
类型没有表示大小要求。但是,
标头提供了额外的精确宽度整数类型int8_t
、int16_t
、int32_t
、int64_t
及其无符号对应项:The C99 standard specifies the content of header
<limits.h>
in the following way :There are no size requirements expressed on the
int
type.However, the
<stdint.h>
header offer the additional exact-width integer typesint8_t
,int16_t
,int32_t
,int64_t
and their unsigned counterpart :POSIX 不涵盖这一点。 ISO C 标准保证类型将能够处理至少一定范围的值,但不保证它们具有特定的大小。
C99 引入的
标头将使您能够访问int16_t
等类型。POSIX doesn't cover that. The ISO C standard guarantees that types will be able to handle at least a certain range of values but not that they'll be of a particular size.
The
<stdint.h>
header introduced with C99 will get you access to types likeint16_t
that do.