JohnCand
JohnCand

Reputation: 1197

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?

Or is it possible for std::numeric_limits<std::size_t>::max() to be larger than std::numeric_limits<std::uintmax_t>::max()?

Upvotes: 24

Views: 4654

Answers (1)

Joseph Mansfield
Joseph Mansfield

Reputation: 110698

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.

Definition of size_t from C++11 §18.2:

The type size_t is an implementation-defined unsigned integer type that is large enough to contain the size in bytes of any object.

Definition of uintmax_t from C99 §7.18.1.5 (it is included in C++ by normative reference):

The following type designates an unsigned integer type capable of representing any value of any unsigned integer type:

uintmax_t

Upvotes: 34

Related Questions