简体   繁体   English

C ++标准是否保证std :: uintmax_t可以保存std :: size_t的所有值?

[英]Does the C++ standard guarantee that std::uintmax_t can hold all values of std::size_t?

Does the C++ standard guarantee (either by explicitly stating it or implicitly by logical deduction) that std::uintmax_t can hold all values of std::size_t ? C ++标准是否保证(通过显式声明它或通过逻辑推导隐式) std::uintmax_t可以保存std::size_t所有值?

Or is it possible for std::numeric_limits<std::size_t>::max() to be larger than std::numeric_limits<std::uintmax_t>::max() ? 或者std::numeric_limits<std::size_t>::max()是否可能大于std::numeric_limits<std::uintmax_t>::max()

Yes. 是。

size_t is defined to be an unsigned integer type large enough to contain the size of any object. size_t被定义为无符号整数类型,其大小足以包含任何对象的大小。 uintmax_t is defined to be able to store any value of any unsigned integer type. uintmax_t被定义为能够存储任何无符号整数类型的任何值。 So if size_t can store it, uintmax_t can store it. 因此,如果size_t可以存储它, uintmax_t可以存储它。

Definition of size_t from C++11 §18.2: 从C ++11§18.2中定义size_t

The type size_t is an implementation-defined unsigned integer type that is large enough to contain the size in bytes of any object. 类型size_t是一个实现定义的无符号整数类型,它足够大,可以包含任何对象的字节大小。

Definition of uintmax_t from C99 §7.18.1.5 (it is included in C++ by normative reference): 的定义uintmax_t从C99§7.18.1.5(它包括在C ++通过标准参考):

The following type designates an unsigned integer type capable of representing any value of any unsigned integer type: 以下类型指定无符号整数类型,能够表示任何无符号整数类型的任何值:

 uintmax_t 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM