gpt4 book ai didi

c++ - "possibly-hypothetical"在指针算术规则中意味着什么?

转载 作者:行者123 更新时间:2023-12-01 19:55:16 26 4
gpt4 key购买 nike

在指针算术标准规范中( [expr.add]/4.2 ,我们有:

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.

这里的“可能假设”是什么意思?该段落已经将结果指针限制在数组的范围内。好吧,包括一过到底的插槽。是这个意思吗?

最佳答案

是的,这是最后一个“元素”。

[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. [..]

关于c++ - "possibly-hypothetical"在指针算术规则中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59592182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com