“可能是假设的"是什么意思?在指针算术规则中意味着什么? [英] What does "possibly-hypothetical" mean in the pointer arithmetic rules?

查看:79
本文介绍了“可能是假设的"是什么意思?在指针算术规则中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在指针算术标准的规范中( [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 + JJ + 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 object x with n elements ([dcl.array]), the expressions P + J and J + P (where J has the value j) point to the (possibly-hypothetical) array element i + j of x if 0 ≤ i + j ≤ n and the expression P - J points to the (possibly-hypothetical) array element i − j of x 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 array x of n elements is considered to be equivalent to a pointer to a hypothetical array element n of x and an object of type T that is not an array element is considered to belong to an array with one element of type T. [..]

这篇关于“可能是假设的"是什么意思?在指针算术规则中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆