在指针算术标准规范中( [expr.add]/4.2
,我们有:
Otherwise, if
P
points to an array element i of an array objectx
with n elements ([dcl.array]), the expressionsP + J
andJ + P
(whereJ
has the value j) point to the (possibly-hypothetical) array element i + j ofx
if 0 ≤ i + j ≤ n and the expressionP - J
points to the (possibly-hypothetical) array element i − j ofx
if 0 ≤ i − j ≤ n.
这里的“可能假设”是什么意思?该段落已经将结果指针限制在数组的范围内。好吧,包括一过到底的插槽。是这个意思吗?
最佳答案
是的,这是最后一个“元素”。
[basic.compound]/3:
[..] For purposes of pointer arithmetic ([expr.add]) and comparison ([expr.rel], [expr.eq]), a pointer past the end of the last element of an arrayx
of n elements is considered to be equivalent to a pointer to a hypothetical array element n ofx
and an object of typeT
that is not an array element is considered to belong to an array with one element of typeT
. [..]
关于c++ - "possibly-hypothetical"在指针算术规则中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59592182/