Untitled diff

Created Diff never expires
38 removals
15 lines
48 additions
24 lines
When an expression that has integer type is added to or subtracted from a pointer,the
When an expression that has integral type is added to or subtracted from a pointer, the result has the type
result has the type of the pointer operand. If the pointer operand points to an element of
of the pointer operand. If the pointer operand points to an element of an array object, and the array is
an array object, and the array is large enough, the result points to an element offset from
large enough, the result points to an element offset from the original element such that the difference of
the original element such that the difference of the subscripts of the resulting and original
the subscripts of the resulting and original array elements equals the integral expression. In other words, if
array elements equals the integer expression. In other words, if the expression P points to
the expression P points to the i-th element of an array object, the expressions (P)+N (equivalently, N+(P))and (P)-N (where N has the value n) point to, respectively, the i + n-th and i − n-th elements of the array
the i-th element of an array object, the expressions (P)+N (equivalently, N+(P))and
object, provided they exist. Moreover, if the expression P points to the last element of an array object,
(P)-N (where N has the value n)point to, respectively,the i+n-th and i−n-th elements of
the expression (P)+1 points one past the last element of the array object, and if the expression Q points
the array object, provided theyexist. Moreover, ifthe expression P points to the last
one past the last element of an array object, the expression (Q)-1 points to the last element of the array
element of an array object, the expression (P)+1 points one past the last element of the
object. If both the pointer operand and the result point to elements of the same array object, or one past
array object, and if the expression Q points one past the last element of an array object,
the last element of the array object, the evaluation shall not produce an overflow; otherwise, the behavior is
the expression (Q)-1 points to the last element of the array object. If both the pointer
undefined.
operand and the result point to elements of the same array object, or one past the last
6 When two pointers to elements of the same array object are subtracted, the result is the difference of the
element of the array object, the evaluation shall not produce an overflow; otherwise, the
subscripts of the two array elements. The type of the result is an implementation-defined signed integral
behavior is undefined. If the result points one past the last element of the array object, it
type; this type shall be the same type that is defined as std::ptrdiff_t in the <cstddef> header (18.2). As
shall not be used as the operand of a unary * operator that is evaluated.
with any other arithmetic overflow, if the result does not fit in the space provided, the behavior is undefined.
In other words, if the expressions P and Q point to, respectively, the i-th and j-th elements of an array object,
the expression (P)-(Q) has the value i − j provided the value fits in an object of type std::ptrdiff_t.
Moreover, if the expression P points either to an element of an array object or one past the last element of
an array object, and the expression Q points to the last element of the same array object, the expression
((Q)+1)-(P) has the same value as ((Q)-(P))+1 and as -((P)-((Q)+1)), and has the value zero if the
expression P points one past the last element of the array object, even though the expression (Q)+1 does not
point to an element of the array object. Unless both pointers point to elements of the same array object, or
one past the last element of the array object, the behavior is undefined.
86