“可能是假设的"是什么意思?在指针算术规则中意味着什么? [英] What does "possibly-hypothetical" mean in the pointer arithmetic rules?
问题描述
在指针算术标准的规范中( [expr.add]/4.2
,我们有:
In the standard's specification for pointer arithmetic ([expr.add]/4.2
, we have:
否则,如果
P
指向具有 n 个元素([dcl.array])的数组对象x
的数组元素 i ,则表达式P + J
和J + P
(其中J
的值为 j )指向x
的(可能是假设的)数组元素 i + j (如果 0≤i + j≤n ,如果 0≤i-,则表达式P - J
指向x
的(可能是假设的)数组元素 i − j . j≤n .
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.
可能是假设的"在这里是什么意思?该段落已经将结果指针限制在数组的范围内.好吧,包括最后一个插槽.这就是它的意思吗?
What does "possibly-hypothetical" mean here? The passage already constrains the resulting pointer to be in range of the array. Well, including the one-past-the-end slot. Is that what it's referring to?
推荐答案
是的,它是最后一个元素".
Yes, it's the one-past-the-end "element".
[basic.compound]/3:
[. ] 出于指针算术([expr.add])和比较([expr.rel],[expr.eq])的目的,指针越过 n 元素被视为等效于指向x
的假设数组元素 n 的指针,并且将非数组元素的T
类型的对象视为属于具有一个T
类型的元素的数组. [..]
[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
. [..]
这篇关于“可能是假设的"是什么意思?在指针算术规则中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!