Sujet : Re: technology discussion → does the world need a "new" C ?
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 06. Jul 2024, 19:28:54
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6c2d7$3tko2$2@dont-email.me>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla Thunderbird
On 7/6/24 03:23, Lawrence D'Oliveiro wrote:
On Fri, 05 Jul 2024 11:46:38 -0700, Keith Thompson wrote:
No, arrays are not pointers.
Except array indexing is designed to be indistinguishable from pointer
arithmetic.
Actually, C doesn't have array indexing; it only has pointer indexing.
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, but
since it's been converted to a pointer, it is actually pointer indexing.
The key point is that an expression of array type does not always get
converted into a pointer to the first element of that array. The clause
above starts out with four exceptions, and an array behaves quite
differently from a pointer when any of those exceptions apply.