c - 为什么 int_fast16_t 在 64 位系统上是 64 位?

标签 c stdint cstdint

我查看了头文件 <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_tint_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/

相关文章:

c++ - C++ 中的 long long int 与 long int 与 int64_t

c - 为什么 atoi 给我一个段错误?

c++ - 通过软件提高 IR 串行可靠性

c - 您如何处理进程的内存限制和性能改进。

c++ - 为什么可能丢失数据的赋值不产生编译器警告

c++ - 在命令行上构建时找不到 cstdint 文件

c++ - (C++11) 如果使用 cstdint 类型,g++ 不提供适当的警告 'incorrectly'

c++ - CMake 导入的库行为

c - 与 inttypes.h、fscanf()、fprintf() 不一致

c - uint8_t 在达到 255 后不翻转到 0 无法正常工作