gpt4 book ai didi

c - stdint.h 库中是否包含整数类型 "extended integer types"?

转载 作者:行者123 更新时间:2023-12-02 17:59:41 25 4
gpt4 key购买 nike

我正在学习整数转换等级,但我有一个问题,我经常使用 stdint.h 库,并且我读到的有关“整数转换等级”的内容是:

“任何标准整数类型的等级应大于任何具有相同大小的扩展整数类型的等级。”

据我所知,例如“int”是一个标准整数类型,但使用 stdint.h 我有“int32_t”,它等于“int”

我知道 stdint.h 库使用“typedef”,因此理论上 int 和 int32_t 是相等的,但我在论坛中读到“扩展整数类型”使用 (u)intxx_t 来引用

所以我的问题是,stdint.h 库中包含的“精确宽度整数”是“标准整数类型”还是被视为“扩展整数类型”?

感谢您的回答!

最佳答案

stdint.h 中列出的类型不一定是扩展整数类型。

C standard 第 6.2.5 节定义扩展整数类型:

4 There are five standard signed integer types, designated as signed char, short int, int, long int, and long long int. (These and othertypes may be designated in several additional ways, as described in6.7.2.) There may also be implementation-defined extended signed integer types. The standard and extended signed integer types arecollectively called signed integer types.

...

7 The standard signed integer types and standard unsigned integer types are collectivelycalled the standard integer types, the extended signed integer types and extendedunsigned integer types are collectively called the extended integer types.

因此,上面指出扩展整数类型是实现定义的

第 7.20p4 节描述了 stdint.h header 中定义的类型:

For each type described herein that the implementation provides, 261)<stdint.h> shall declare that typedef name and define the associatedmacros. Conversely, for each type described herein that theimplementation does not provide, <stdint.h> shall not declare thattypedef name nor shall it define the associated macros. Animplementation shall provide those types described as ‘‘required’’,but need not provide any of the others (described as ‘‘optional’’).

所以这表明 stdint.h 中的类型是其他类型的 typedef。关键部分是脚注 261,其中指出:

  1. Some of these types may denote implementation-defined extended integer types.

那么无论 stdint.h 中的类型是否被视为标准或扩展整数类型取决于它们的 typedef。

关于c - stdint.h 库中是否包含整数类型 "extended integer types"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74712224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com