This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Array out of bounds warning
- To: Kamil Iskra <kamil at wins dot uva dot nl>
- Subject: Re: Array out of bounds warning
- From: Geoff Keating <geoffk at cygnus dot com>
- Date: 02 Aug 2000 18:12:49 -0700
- CC: gcc at gcc dot gnu dot org
- References: <Pine.LNX.4.10.10008022217510.1359-100000@bubu.home>
Kamil Iskra <kamil@wins.uva.nl> writes:
> On Mon, 31 Jul 2000, Jeffrey A Law wrote:
>
> > > int a[10];
> > > a[10] = 17;
> [snip]
> > The next question in my mind is how often do we get false hits on the
> > warning.
>
> I've been wondering: what will the proposed patch do for n-dimensional
> arrays, say:
>
> int a[10][10];
> a[0][10]=17;
>
> I think right now the code will generate a warning, but is this what we
> want?
>
> I'm not entirely sure whether the standard does allow such a construction,
> but surely it has a well defined meaning, given that the memory layout of
> arrays is precisely defined in the standard. I've seen such a code only
> yesterday, where it was used for speed reasons, so it's probably not an
> uncommon trick.
The behaviour is rendered undefined by the ISO C standard. This is
precisely so that compilers can do bounds-checking on references like
these.
--
- Geoffrey Keating <geoffk@cygnus.com>