gpt4 book ai didi

c++ - C++ 是否保证 cstdint sizeof 的顺序?

转载 作者:搜寻专家 更新时间:2023-10-31 00:31:27 26 4
gpt4 key购买 nike

C++ 标准是否保证:

sizeof(uint8_t) <= sizeof(uint16_t) <= sizeof(uint32_t) <= sizeof(uint64_t)
sizeof(uint_least8_t) <= sizeof(uint_least16_t) <= sizeof(uint_least32_t) <= sizeof(uint_least64_t)
sizeof(uint_fast8_t) <= sizeof(uint_fast16_t) <= sizeof(uint_fast32_t) <= sizeof(uint_fast64_t)

如果没有,它提供什么保证?(欢迎从标准中摘录)

最佳答案

第一个是有保证的,前提是这些类型存在。 (如果系统不能提供它们,它们可能不存在)。

第二个 least 是有保证的。这是未签名案例的文本(签名文本类似):

The typedef name uint_leastN_t designates an unsigned integer type with a width of at least N, such that no unsigned integer type with lesser size has at least the specified width.

第三个,fast:好像没有具体说明,但是写的是:

The typedef name int_fastN_t designates the fastest signed integer type with a width of at least N

如果我们假设这段文字是按字面意思理解的,那么它会给出保证;尽管相关的脚注表明编译器有更多的自由度。尽管如此,一个实现似乎不太可能做类似使 fast16_t 成为 64 位,而 fast32_t 成为 32 位的事情。

注意。这些引用来自 ISO C99,C++ 标准引用了这些定义。

关于c++ - C++ 是否保证 cstdint sizeof 的顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34123006/

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