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
1 个解决方案
#1
30
Yes.
size_t
is defined to be an unsigned integer type large enough to contain the size of any object. uintmax_t
is defined to be able to store any value of any unsigned integer type. So if size_t
can store it, uintmax_t
can store it.
size_t被定义为无符号整数类型,其大小足以包含任何对象的大小。 uintmax_t被定义为能够存储任何无符号整数类型的任何值。因此,如果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):
来自C99§7.18.1.5的uintmax_t的定义(通过规范性引用包含在C ++中):
The following type designates an unsigned integer type capable of representing any value of any unsigned integer type:
以下类型指定无符号整数类型,能够表示任何无符号整数类型的任何值:
uintmax_t
#1
30
Yes.
size_t
is defined to be an unsigned integer type large enough to contain the size of any object. uintmax_t
is defined to be able to store any value of any unsigned integer type. So if size_t
can store it, uintmax_t
can store it.
size_t被定义为无符号整数类型,其大小足以包含任何对象的大小。 uintmax_t被定义为能够存储任何无符号整数类型的任何值。因此,如果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):
来自C99§7.18.1.5的uintmax_t的定义(通过规范性引用包含在C ++中):
The following type designates an unsigned integer type capable of representing any value of any unsigned integer type:
以下类型指定无符号整数类型,能够表示任何无符号整数类型的任何值:
uintmax_t