【发布时间】:2011-12-19 00:11:22
【问题描述】:
一开始可能会想到std::numeric_limits<size_t>::max(),但是如果有一个这么大的对象,它还能提供一个过去的指针吗?我猜不会。这是否意味着sizeof(T) 可以产生的最大值是std::numeric_limits<size_t>::max()-1?我是对的,还是我错过了什么?
【问题讨论】:
-
对象是否需要提供一个过去的指针?
-
@Dabbler:根据 C++ 标准,是的,因为就指针运算而言,对象可以被视为大小为 1 的数组。如果您愿意,我可以查找确切的措辞.
-
@Mike:错了,5.7 §1 说
For the purposes of these operators, a pointer to a nonarray object behaves the same as a pointer to the first element of an array of length one with the type of the object as its element type. -
我没有看到
std::numeric_limits<size_t>::max()large 对象与系统无法提供过去的指针之间的相关性。 -
@Dennis: ...因为 size_t 和 intptr_t 是不同的东西
标签: c++ memory pointers sizeof size-t