mips address+symbol issue.

cgd@broadcom.com cgd@broadcom.com
Fri Jan 23 21:55:00 GMT 2004


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.)

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.

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:

        long tmp;

        tmp = i - 2000000000L;
        return a[tmp];

and:
        char *tmp;

        tmp = &a[-2000000000L];
        return *(tmp + i);              // or just: return tmp[i];


I'd suspect the former is what the order of operations would require,
but the latter is what the compiler's emitting as assembly code.


chris



More information about the Binutils mailing list