c++之size_t 是否与 ptrdiff_t 具有相同的大小和对齐方式
在我的平台上(以及我认为的大多数平台上)std::size_t
和 std::ptrdiff_t
具有相同的大小和相同的对齐方式。有没有哪个平台不是真的?简而言之:标准是否要求?
请您参考如下方法:
In short: is it required by the standard?
不。唯一的要求来自 [support.types.layout]/2它是:
The type ptrdiff_t is an implementation-defined signed integer type that can hold the difference of two subscripts in an array object, as described in [expr.add].
有 paragraph 4
[ Note: It is recommended that implementations choose types for ptrdiff_t and size_t whose integer conversion ranks are no greater than that of signed long int unless a larger size is necessary to contain all the possible values. — end note ]
但注释是非规范性的,它只是一个建议,而不是一个要求。
std::size_t
被定义为
The type size_t is an implementation-defined unsigned integer type that is large enough to contain the size in bytes of any object ([expr.sizeof]).
在 paragraph 3并且它也没有要求它们是相同的。
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。