Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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()?

like image 351
JohnCand Avatar asked Apr 04 '13 23:04

JohnCand


People also ask

What is the difference between Size_t and std :: Size_t?

So yeah, both are same; the only difference is that C++ defines size_t in std namespace.

Is Size_t signed C++?

Yes, size_t is guaranteed to be an unsigned type.

What is Size_t C++?

size_t type is a base unsigned integer type of C/C++ language. It is the type of the result returned by sizeof operator. The type's size is chosen so that it can store the maximum size of a theoretically possible array of any type. On a 32-bit system size_t will take 32 bits, on a 64-bit one 64 bits.


1 Answers

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 
like image 159
Joseph Mansfield Avatar answered Oct 11 '22 23:10

Joseph Mansfield