Sujet : Re: technology discussion → does the world need a "new" C ?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 06. Jul 2024, 23:38:14
Autres entêtes
Organisation : None to speak of
Message-ID : <87h6d2uox5.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8
User-Agent : Gnus/5.13 (Gnus v5.13)
BGB <
cr88192@gmail.com> writes:
On 7/6/2024 2:23 AM, 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.
>
Yeah, and in the 1D case, an array can be seen as functionally an
implicitly defined pointer with an assigned size and preassigned
backing memory.
No, there is no implicitly defined pointer.
Consider:
int integer_object;
int array_object[10];
This create an object of integer type with size sizeof(int) and an
object of array type with size 10 * sizeof (int). There is no implicit
pointer object associated with it either of them.
If you evaluate the expression `array_object` in most contexts, it's
implicitly converted to a pointer *value*, pointing to the 0th element
of the array object. There is still no implicit pointer object.
Similarly, evaluating `&integer_object` yields a pointer value, but does
not allocate a pointer object (but the "&" operator has to be explicit).
In very early C, before K&R1, an array object declaration actually did
implicitly create a pointer object holding the address of its initial
element. This became unworkable for structs containing members of
struct type; copying a struct would copy the address of the array but
not the array itself, resulting in the two structs sharing the same
array data.
Granted, C generally allows one to see the backing memory, but not the
implicit pointer to said backing memory. I guess one could argue that
if one can't take the address of it, it doesn't exist, but yeah...
>
Kind of a similar feature with lvalue structs:
An implicit pointer exists...
But, C wont let you see it directly or take its address.
If you take the address of a struct object, you get a pointer *value*.
There is no implicit pointer *object*, so there's nothing whose address
can be taken.
If you assume that arrays are really pointers, it's difficult or
impossible to build a consistent model of how C works. If instead you
realize that arrays are arrays and arrays are pointers, and that C has
some peculiar rules about their interaction, everything is peculiar but
consistent.
[...]
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */