This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: mips address+symbol issue.
On Fri, Jan 23, 2004 at 01:54:49PM -0800, cgd@broadcom.com wrote:
> At 23 Jan 2004 16:20:27 -0500, Ian Lance Taylor wrote:
> > (My understanding is that the C standard doesn't even permit you to
> > form the address of an out-of-bounds array access. Doing so moves you
> > out of the range of standardized behaviour, and no promises are made.)
I believe that is correct.
>
> FWIW, looking at the test case, and not being a language lawyer, i
> don't know that it *does* form the address of an out-of-bounds array
> access.
It does.
>
> the test case is:
>
> char a[10] = "deadbeef";
>
> char
> acc_a (long i)
> {
> return a[i-2000000000L];
> }
>
> main ()
> {
> if (acc_a (2000000000L) != 'd')
> abort ();
> exit (0);
> }
>
>
> Two ways to interpret this, i guess:
There are many ways to interpret one could interpret it, but the
interpretation that I believe is the correct is the following:
Remember that a[i] is just syntactic sugar for *(a+i).
This means that the expression a[i-2000000000L] is the same as
*(a+i-2000000000L). With i==2000000000L, this becomes
*(a+2000000000L-2000000000L) which is the same as
*((a+2000000000L)-2000000000L).
a+2000000000L is *not* a valid address, and thus undefined behaviour is
invoked.
--
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se