Sujet : Re: technology discussion → does the world need a "new" C ?
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.cDate : 10. Jul 2024, 07:38:39
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6la9f$1q63l$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla Thunderbird
On Sat, 6 Jul 2024 19:53:56 +0100, bart wrote:
On 06/07/2024 19:28, James Kuyper wrote:
>
... 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).
This is really, really pedantic. Even gcc doesn't get it right in that
case, because if I try and compile this:
int a, b> a[b];
it says:
error: subscripted value is neither array nor pointer nor vector
There is no expression that has the type "array of type" in the above
code. How is that relevant to what I wrote?
For the subscript operator:
"One of the expressions shall have type "pointer to complete object
type", the other expression shall have integer type," (6.5.2.1p1)
Neither a nor b has the type "pointer to complete object type". Both a
and b have the type 'int'. How did you expect that code to be meaningful?
Note that a[&b] would be valid, since &b is treated for this purpose as
a pointer to the first element of a 1-element array.
Note that the standard doesn't mandate which expression have the pointer
type; that's because a[&b] is defined as *(a + &b), and you can add a
pointer to an integer in either order, so you can subscript an array as
array[5] or 5[array].
'Subscripting' I think we can agree is the same thing as 'indexing':
what those funny square brackets do.
I can agree that subscripting is indeed what those square brackets do.
The C standard never mentions indexing, but I do agree that there is a
correspondence. However, if you derive any conclusions from that
correspondence that contradict what the C standard says about
subscripting, those conclusions are invalid.