Q: What is the largest value of sizeof (T)?
A: std::numeric_limits<size_t>::max()
Obviously, sizeof cannot return a value greater than std::numeric_limits<size_t>::max() , since it does not fit. The only question is, can it return ...::max() ?
Yes. Here is a valid program that does not violate the limitations of the C ++ 03 standard, which demonstrates the proof. In particular, this program does not violate any restrictions listed in clause 5.3.3 [expr.sizeof], as well as in ยง8.3.4 [dcl.array]:
#include <limits> #include <iostream> int main () { typedef char T[std::numeric_limits<size_t>::max()]; std::cout << sizeof(T)<<"\n"; }
Robแตฉ
source share