ARM cortex-M3 uint_fast32_t 与 uint32_t [英] ARM cortex-M3 uint_fast32_t vs uint32_t

查看:51
本文介绍了ARM cortex-M3 uint_fast32_t 与 uint32_t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 STM32Fx cortex-M3 系列处理器开发程序.在 stdint.h 中定义了以下内容:

I am developing a program for an STM32Fx cortex-M3 series processor. In stdint.h the following are defined:

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) <= sizeof(unsigned long) 和 UINT_MAX <= ULONG_MAX - 总是.

Also as far as i know sizeof(unsigned int) <= sizeof(unsigned long) and UINT_MAX <= ULONG_MAX - always.

因此,我希望 uint_fast32_t 是大小等于或大于 uint32_t 大小的数据类型.

Thus I would expect uint_fast32_t to be a data type with a size equal to or greater than the size of uint32_t.

在 cortex-M3 sizeof(unsigned int) == sizeof(unsigned long) == 4 的情况下.因此上述定义在大小方面是正确的".

In the case of the cortex-M3 sizeof(unsigned int) == sizeof(unsigned long) == 4. So the above definitions are 'correct' in terms of size.

但是为什么它们没有以与底层数据类型的名称和逻辑大小一致的方式定义,即

But why are they not defined in a way that is consistent with the names and logical sizes of the underlying data types i.e.

typedef unsigned long uint_fast32_t;
typedef unsigned int  uint_least32_t;
typedef uint_fast32_t uint32_t;

有人可以澄清基础类型的选择吗?

Can someone please clarify the selection of the underlying types?

鉴于 'long' 和 'int' 的大小相同,为什么不为所有三个定义使用相同的数据类型?

Given that 'long' and 'int' are the same size, why not use the same data type for all three definitions?

typedef unsigned int uint_fast32_t;
typedef unsigned int uint_least32_t;
typedef unsigned int uint32_t;

推荐答案

这样的话,只保证

sizeof(long) >= sizeof(int)

并且不能保证它实际上不再存在.在很多系统上,int 通常和 long 一样大.

and it is not guaranteed that it is actually any longer. On a lot of systems, int is usually as big as long.

这篇关于ARM cortex-M3 uint_fast32_t 与 uint32_t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆