c++ - 来自 stdint.h 的快速类型的溢出行为

标签 c++ c c++11 c99

C99 和 C++11(以及之前的 POSIX)在 stdint header 中引入了 leastfast 类型,例如int_fast16_tuint_fast8_t

我想知道这些类型的溢出行为有什么保证。如果这些与“普通”整数类型相同(以便无符号类型在溢出时环绕),我想知道 uint_fast8_t 实际上可以映射到与 fixed-witdh 不同的任何类型uint8_t 类型,因此速度更快。

最佳答案

C11 n1570 表示

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 .


因此,没有任何行为是可以保证的;这些说的是 int_fastN_t 不能在 2^(n-1) - 1 ... 2^(n-1) 范围内有符号溢出- 1; uint_fastN_t 不得对小于 2^n - 1 的值进行环绕。如果您需要更精确的环绕行为,则不要使用快速类型,而是使用精确宽度类型(又名 intN_tuintN_t)。

关于c++ - 来自 stdint.h 的快速类型的溢出行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37204901/

相关文章:

c++ - c++11 中的 brace-init 是否存在任何效率问题?

c++ - 将 std::string 转换为 const char* 供 printf 消费

c++ - 代码崩溃,没有逻辑错误

c++ 用于unix命令行操作

用于信号处理的 C++ 库

c - 在c中的结构中使用union的目的

c++ - rdstate() 返回值是什么意思?

c++ - `catch`语句在没有反射的情况下如何识别异常类型?

c - 在 C 中读取多行

c - Malloc 时出现段错误 11