我查看了头文件 <stdint.h>
关于我的实现。我看到以下内容:
typedef long int int_fast16_t;
typedef long int int_fast32_t;
typedef long int int_fast64_t;
我的系统是64位,所以long int占用64位。为什么所有三种数据类型都定义为长整型?我了解 int_fast64_t 的情况,它是 64 位。但为什么 16 位和 32 位数据类型是 64 位呢?这是某种错误吗?我创建了一个小程序来检查是否是这种情况:
sizeof(int_fast8_t) : 1
sizeof(int_fast16_t) : 8
sizeof(int_fast32_t) : 8
sizeof(int_fast64_t) : 8
这些数据类型实现的大小是否已定义?哪些特征或特征将数据类型定义为“快速”?是数据 block 从 RAM 加载到 CPU 的速度吗?如果int_fast16_t
和int_fast32_t
8字节宽,对性能有什么好处?在 64 位系统上访问 64 位数据类型真的更快吗?
最佳答案
这些类型没有固定大小。它们是至少给定大小的类型,往往是最快的。
这些类型在 C 标准第 7.20.1.3 节中定义:
1 Each of the following types designates an integer type that is usually fastest to operate with among all integer types that have at least the specified width.
2 The typedef name int_fastN_t designates the fastest signed integer type with a width of at least N. The typedef name uint_fastN_t designates the fastest unsigned integer type with a width of at least N.
关于c - 为什么 int_fast16_t 在 64 位系统上是 64 位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51178314/