什么是uint_fast32_t,为什么应使用它代替常规的int和uint32_t? [英] What is uint_fast32_t and why should it be used instead of the regular int and uint32_t?
问题描述
所以使用 typedef
:ed原始数据类型的原因是抽象了低级表示形式并使其易于理解( uint64_t
而不是 long long
类型,即8个字节)。
So the reason for typedef
:ed primitive data types is to abstract the low-level representation and make it easier to comprehend (uint64_t
instead of long long
type, which is 8 bytes).
但是,有 uint_fast32_t
具有相同的 typedef
为 uint32_t
。
However, there is uint_fast32_t
which has the same typedef
as uint32_t
. Will using the "fast" version make the program faster?
推荐答案
-
在某些平台上,int
可能小到16位。 -
uint32_t
不保证存在。 实现必须提供一个可选的 -
uint_fast32_t
清楚地表明您的意图:至少是 32位类型,从性能的角度来看这是最好的。uint_fast32_t
实际上可能是64位长。 int
may be as small as 16 bits on some platforms. It may not be sufficient for your application.uint32_t
is not guaranteed to exist. It's an optionaltypedef
that the implementation must provide iff it has an unsigned integer type of exactly 32-bits. Some have a 9-bit bytes for example, so they don't have auint32_t
.uint_fast32_t
states your intent clearly: it's a type of at least 32 bits which is the best from a performance point-of-view.uint_fast32_t
may be in fact 64 bits long. It's up to the implementation.
typedef
,前提是该实现必须具有准确的32位无符号整数类型。例如,有些文件有9位字节,因此它们没有 uint32_t
。
...有
uint_fast32_t code>与
uint32_t
具有相同的typedef ...
... there is
uint_fast32_t
which has the same typedef asuint32_t
...
您正在寻找的不是标准。这是一种特殊的实现方式(BlackBerry)。因此,您不能从那里推断 uint_fast32_t
始终与 uint32_t
相同。
What you are looking at is not the standard. It's a particular implementation (BlackBerry). So you can't deduce from there that uint_fast32_t
is always the same as uint32_t
.
另请参见:
这篇关于什么是uint_fast32_t,为什么应使用它代替常规的int和uint32_t?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!