This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Why convert to pointer type before added to a pointer
- From: "Rupert Wood" <me at rupey dot net>
- To: "'Jie Zhang'" <zhangjie at magima dot com dot cn>,<gcc at gcc dot gnu dot org>
- Date: Mon, 16 Aug 2004 11:30:27 +0100
- Subject: RE: Why convert to pointer type before added to a pointer
Jie Zhang wrote:
Well (to my untrained eye) this looks like:
> n.0 = (unsigned int)n;
> T.1 = n.0 * 4;
Compute the byte-offset for the index as an unsigned integer.
> T.2 = (int *)T.1; <== Why this converting
This isn't really an int* - it's more logically ptrdiff_t. It's the array
offset in bytes; it's going to be added to a, which is int*, so I guess
GIMPLE wants the offset as an int* too and requires a new temporary for the
conversion.
> T.3 = T.2 + a;
> *T.3 = 1;
Finish computing &(a[n]) in T.3 and then set the value.
Please forgive my ignorance, but -
Performing the index computation as unsigned looks wrong to me. I suspect
this because sizeof(int) is unsigned, but isn't a[-1] acceptable? I can't
navigate the C standard well enough to see what it says.
Rup.