gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 01:22:55 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com