The standard only defines lower bounds for the limits of integers. For example, the lower bound for the maximum that an unsigned long
can represent is 4294967295
.
std::numeric_limits<unsigned long>::max()
gives the implementation-defined maximum value an unsigned long
can represent (i.e. what the current implementation aka compiler/linker/etc actually supports).
This means it is required that
std::numeric_limits<unsigned long>::max()
gives a value that is 4294967295
or more. There is nothing preventing it giving a larger result. However, an implementation that gives a smaller result is non-compliant with the standard.
Note that, when moving between compilers, the only guarantee is "4294967295
or more". If one implementation gives a larger value, there is no guarantee that another implementation will.
For the most part, the standard actually says nothing whatsoever about the number of actual bits used to represent the basic integral types, like unsigned long
.
The value 18446744073709551615
is consistent with a 64-bit unsigned long
, in practice.
Similar stories, albeit with different values, for other integral types (int
, char
, short
, long
, etc).