What is uint_fast32_t and why should it be used instead of the regular int and uint32_t?(什么是 uint_fast32_t,为什么要使用它而不是常规的 int 和 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
与 uint32_t
具有相同的 typedef
.使用快速"版本会使程序更快吗?
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
不保证存在.它是一个可选的typedef
,如果它具有恰好 32 位的无符号整数类型,则实现必须提供它.例如,有些具有 9 位字节,因此它们没有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.标准委员会关心的异国架构.
... 有 uint_fast32_t
与 uint32_t
具有相同的 typedef ...
... there is
uint_fast32_t
which has the same typedef asuint32_t
...
你看的不是标准.这是一个特定的实现(黑莓).所以你不能从那里推断出 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
.
另见:
我对 C 和 C++ 中整数类型的基于意见的实用观点.
这篇关于什么是 uint_fast32_t,为什么要使用它而不是常规的 int 和 uint32_t?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:什么是 uint_fast32_t,为什么要使用它而不是常规的 int 和 uint32_t?
基础教程推荐
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 从 std::cin 读取密码 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01