(part 45) Han from China answers your C questions
- From: George Orwell <nobody@xxxxxxxxxxxx>
- Date: Thu, 27 Nov 2008 00:01:21 +0100 (CET)
Mr. Tarasevich said:
Borked Pseudo Mailed wrote:
....
Is there some *clear*, *unambiguous* statement that says any
instance of an object of type T can be thought of as an array of one
element of type T?
For the purpose of address arithmetics - yes, that's exactly what the
standard states in "6.5.6 Additive operators".
Ah, but dear Tarasevich, that is why I put the emphasis on
*clear* and *unambiguous*. 6.5.6 (7) says only
"For the purposes of these operators, a pointer to an object
that is not an element of an array behaves the same as a pointer
to the first element of an array of length one with the type
of the object as its element type."
Now, I know what the *glaringly obvious* interpretation of that is,
but I'd rather we be, you know, completely precise.
If the relative pronoun 'that' restricts the word 'pointer' as
opposed to 'object', we get the following:
int *i; // pointer to an object and isn't an element of an array
// i.e., isn't like p[0] for int *p[100]
int a[1]; // array of length one sharing same type
Notice no pointed-to object involved. It's just telling us in the abstract
that i + 1 and a + 1 behave the same in terms of, say, byte size of
increment. So that you could do...
i = a;
and have i + 1 be the same as a + 1, which in this case is legal.
There's no implication that
int j;
int *i = &j;
i++;
results in anything but undefined behavior.
I know what SEEMS obvious, but I prefer my C99 standard to be
precise to the max. It's dangerous to make assumptions based on
what SEEMS obvious. We can't rule out an apparently absurd
interpretation if it's still a logically consistent reading
of the postmodern 'text'.
Yours,
Han from China
Il mittente di questo messaggio|The sender address of this
non corrisponde ad un utente |message is not related to a real
reale ma all'indirizzo fittizio|person but to a fake address of an
di un sistema anonimizzatore |anonymous system
Per maggiori informazioni |For more info
https://www.mixmaster.it
.
- Prev by Date: (part 45) Han from China answers your C questions
- Next by Date: Re: (part 45) Han from China answers your C questions
- Previous by thread: Re: (part 45) Han from China answers your C questions
- Next by thread: (part 45) Han from China answers your C questions
- Index(es):
Relevant Pages
|