additive-expression: multiplicative-expression additive-expression + multiplicative-expression additive-expression - multiplicative-expression
1144 For addition, either both operands shall have arithmetic type, or one operand shall be a pointer to an object type and the other shall have integer type.
1145 (Incrementing is equivalent to adding 1.)
1146 For subtraction, one of the following shall hold:
1147 88) This is often called truncation toward zero.
1148 both operands have arithmetic type;
1149 both operands are pointers to qualified or unqualified versions of compatible object types; or
1150 the left operand is a pointer to an object type and the right operand has integer type.
1151 (Decrementing is equivalent to subtracting 1.)
1152 If both operands have arithmetic type, the usual arithmetic conversions are performed on them.
1153
The result of the binary
1154
The result of the binary
1155 For the purposes of these operators, a pointer to an object that is not an element of an array 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.
1156 When an expression that has integer type is added to or subtracted from a pointer, the result has the type of the pointer operand.
1157 If the pointer operand points to an element of an array object, and the array is large enough, the result points to an element offset from the original element such that the difference of the subscripts of the resulting and original array elements equals the integer expression.
1158
In other words, if the expression
1159
Moreover, if the expression
1160 If both the pointer operand and the result point to elements of the same array object, or one past the last element of the array object, the evaluation shall not produce an overflow;
1161 otherwise, the behavior is undefined.
1162
If the result points one past the last element of the array object,
it shall not be used as the operand of a unary
1163 When two pointers are subtracted, both shall point to elements of the same array object, or one past the last element of the array object;
1164 the result is the difference of the subscripts of the two array elements.
1165
The size of the result is implementation-defined, and its type (a
signed integer type) is
1166 If the result is not representable in an object of that type, the behavior is undefined.
1167
In other words, if the expressions
1168
Moreover, if the expression
1169 EXAMPLE Pointer arithmetic is well defined with pointers to variable length array types.
{
int n = 4, m = 3;
int a[n][m];
int (*p)[m] = a; // p == &a[0]
p += 1; // p == &a[1]
(*p)[2] = 99; // a[1][2] == 99
n = p - a; // n == 1
}
If array
1170
Forward references:
array declarators (6.7.5.2), common definitions
Next
Created at: 2005-06-29 02:19:00
The text from WG14/N1124 is copyright © ISO