(part 45) Han from China answers your C questions



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

.



Relevant Pages

  • (part 45) Han from China answers your C questions
    ... instance of an object of type T can be thought of as an array of one ... For the purpose of address arithmetics - yes, ... Ah, but dear Tarasevich, that is why I put the emphasis on ... "For the purposes of these operators, a pointer to an object ...
    (comp.lang.c)
  • (part 45) Han from China answers your C questions
    ... instance of an object of type T can be thought of as an array of one ... For the purpose of address arithmetics - yes, ... Ah, but dear Tarasevich, that is why I put the emphasis on ... "For the purposes of these operators, a pointer to an object ...
    (comp.lang.c)
  • Re: (part 45) Han from China answers your C questions
    ... Nomen Nescio writes: ... instance of an object of type T can be thought of as an array of one ... For the purpose of address arithmetics - yes, ... "For the purposes of these operators, a pointer to an object ...
    (comp.lang.c)
  • Re: Binary Read Method?
    ... System.IO.File.ReadAllBytesmethod will read the entire file into an array ... You will also need a 'pointer' that always indicates the next byte to be ... Your processing loop now becomes: ... for this purpose. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: char **argv & char *argv[]
    ... "pointer to pointer to char". ... >> pointer)) pointing to the first element of an array. ... so we have to start adding more context. ... type "pointer to char", rather than "array MISSING_SIZE of char". ...
    (comp.lang.c)