This is the mail archive of the gcc-patches@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]

Re: PATCH: BPs & cleanups for ARRAY_SIZE


Raja R Harinath <harinath@cs.umn.edu> writes:

> But, isn't that allowed in C?
> 
>   int a[3][3][3];
>   p = (int *) a;
> 
> 'p' should get the same bounds as 'a':
> 
>   [ (char *)a, (char *)a + 27*sizeof(int) )
> 
> Then, there's no violation of bounds if 'p' is stepped 27 times,
> instead of nested loops.

ISO/IEC 9899/1999 (E)

                       Programming languages  --  C

	Annex J (informative)
	Portability Issues
...
       J.2  Undefined behavior

       The behavior is undefined in the following circumstances:
...
         -- An  array  subscript is out of range, even if an object
            is apparently accessible with the given  subscript  (as
            in  the lvalue expression a[1][7] given the declaration
            int a[4][5]) (6.5.6).

Greg

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