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

标签 c++ pointers language-lawyer pointer-arithmetic

在指针算术标准规范中( [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/

相关文章:

C++ 三维 vector ?

c - 为什么 C 中函数类型声明后面有一个星号?

c++ - 混合内联和构造函数初始化的初始化顺序

C++使用lambda进行隐式构造函数调用,期望函数指针

c++ - 为什么使用检测惯用法会导致 Clang 和 GCC 出现不同的编译错误,而 MSVC 则不会出现编译错误

c++ - 如何使用 GLM vector 关系函数?

C++ thread_id 是什么数据类型,它可以分配给变量吗?

c++ - ReadFile std::unique_ptr 对比 std::vector 对比 std::string

c - 在c中读取文件指针,如果EOF则返回null

c++ - 如果我们删除 [-Wreturn-local-addr] 可以吗(警告 : address of local variable returned) by using static keyword in c++?