At first one might think std::numeric_limits<size_t>::max(), but if there was an object that huge, could it still offer a one-past-the-end pointer? I guess not. Does that imply the largest value sizeof(T) could yield is std::numeric_limits<size_t>::max()-1? Am I right, or am I missing something?
At first one might think std::numeric_limits<size_t>::max() , but if there was an object that
Share
A:
std::numeric_limits<size_t>::max()Clearly, sizeof cannot return a value larger than
std::numeric_limits<size_t>::max(), since it wouldn’t fit. The only question is, can it return...::max()?Yes. Here is a valid program, that violates no constraints of the C++03 standard, which demonstrates a proof-by-example. In particular, this program does not violate any constraint listed in §5.3.3 [expr.sizeof], nor in §8.3.4 [dcl.array]: