P
Paul
Leigh Johnston said:On 14/02/2011 14:40, James Kanze wrote:Just because an array can decay to a pointer does not mean that arrays
are the same as pointers.I know that, and you know that I know that. On the other hand,
there is no "array index operator" which operates on an array.
To index into an array, you have to convert the array to
a pointer, and use pointer arithmetic.A compiler can optimize indexing into a local array as direct memory
read of the stack (i.e. offsetting the stack pointer) without performing
any pointer arithmetic at all.Please cite the part of the Standard which says that indexing into an
array *requires* converting the array into a pointer. Although the
array/pointer *equivalence* exists it is not a *requirement* that such
*equivalence* always be utilized by a compiler (implementation) as far
as I can tell (I could be wrong; I am not familiar with the entire
Standard).
§5.2.1:
A postfix expression followed by an expression in square
brackets is a postfix expression. One of the expressions
shall have the type “pointer to T” and the other shall
have enumeration or integral type. The result is an
lvalue of type “T.” The type “T” shall be
a completely-defined object type. The expression E1[E2]
is identical (by definition) to *((E1)+(E2)).
It's the definition of the [] operator. (Note that this allows
things like 1["abc"].)
That simply defines an *equivalence*; an implementation is not required to
utilize such *equivalence* when subscripting an array.
§8.3.4/6:
"if E1 is an
array and E2 an integer, then E1[E2] refers to the E2-th member of E1."
An integer is a whole number positive or negative, the above confirms that
E2 can be an integer and therefore can be negative.
ergo E2 cannot be negative ergo you cannot have negative array indices.
Your twisted misinterpretation would redefine the meaning of integer.