我正在为 STM32Fx cortex-M3 系列处理器开发一个程序。在 stdint.h 中定义了以下内容:
typedef unsigned int uint_fast32_t;
typedef uint32_t uint_least32_t;
typedef unsigned long uint32_t;
据我了解。
[u]int_fast[n]_t will give you the fastest data type of at least n bits.
[u]int_least[n]_t will give you the smallest data type of at least n bits.
[u]int[n]_t will give you the data type of exactly n bits.
据我所知, sizeof(unsigned int)
因此,我希望 uint_fast32_t 是一种大小等于或大于 uint32_t 大小的数据类型。
在 cortex-M3 sizeof(unsigned int) == sizeof(unsigned long) == 4 的情况下。因此,上述定义在大小方面是“正确的”。
但为什么它们的定义方式不与底层数据类型的名称和逻辑大小一致,即
typedef unsigned long uint_fast32_t;
typedef unsigned int uint_least32_t;
typedef uint_fast32_t uint32_t;
有人可以澄清底层类型的选择吗?
鉴于“long”和“int”大小相同,为什么不对所有三个定义使用相同的数据类型呢?
typedef unsigned int uint_fast32_t;
typedef unsigned int uint_least32_t;
typedef unsigned int uint32_t;