>>No.60425375
指针加减行为这事情还是不太可能有改动的,尤其是C这种很保守的语言
C99的标准文本https://busybox.net/~landley/c99-draft.html#6.5.6
我不我发帖的时候看漏了一条,就是两个链接上面的条文
For the purposes of these operators, a pointer to a nonarray object behaves the same as a pointer to the first element of an array of length one with the type of the object as its element type.
(C++也有类似的脚注)
也就是说对于C/C++而言,&a+1这个表达式都是良构的
但是,这时候 &a+1 指向的是不存在的对象,这个指针只能减回去/作差/比大小,对它进行解引用是UB
或者按照C的标准文本:
If the result points one past the last element of the array object, it shall not be used as the operand of a unary * operator that is evaluated.
按照C++也一样,解引用非指向完整的对象的指针是非法的(只有指向对象或函数头的指针是可以解引用的),于是依然是UB(^o^)ノ
至于为什么这个奇怪的指向不存在对象的指针要允许它是合法的指针大概是为了和迭代器行为一致保证的...这些都是语言设计的破事了
但是总而言之,*(&a+1)构成UB!