This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]