Liste des Groupes | Revenir à cl c |
On 7/6/24 03:23, Lawrence D'Oliveiro wrote:This is really, really pedantic. Even gcc doesn't get it right in that case, because if I try and compile this:On Fri, 05 Jul 2024 11:46:38 -0700, Keith Thompson wrote:Actually, C doesn't have array indexing; it only has pointer indexing.
>No, arrays are not pointers.>
Except array indexing is designed to be indistinguishable from pointer
arithmetic.
The subscript operator requires that one of it's operands shall have the
type "pointer to a complete object type", and that the other shall have
integer type. It cannot be applied to arrays; but conveniently, the
standard mandates that:
"Except when it is the operand of the sizeof operator, or typeof
operators, or the unary & operator, or is a string literal used to
initialize an array, an expression that has type "array of type" is
converted to an expression with type "pointer to type" that points to
the initial element of the array object ..." (6.3.2.1p3).
It is that conversion which creates the illusion of array indexing, butIsn't that how all languages work 'under the hood'? The net affect from the user's point of view is that you have an array object, and use 'indexing' to access its individual elements.
since it's been converted to a pointer, it is actually pointer indexing.
Les messages affichés proviennent d'usenet.