This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc 4.8.1: -O2 warnings one element off
- From: Andrew Haley <aph at redhat dot com>
- To: Jens Bauer <jens-lists at gpio dot dk>
- Cc: gcc at gcc dot gnu dot org
- Date: Sat, 01 Jun 2013 22:12:51 +0100
- Subject: Re: gcc 4.8.1: -O2 warnings one element off
- References: <20130601230821231127 dot ebd41391 at gpio dot dk>
On 06/01/2013 10:08 PM, Jens Bauer wrote:
> I would expect gcc to complain when it meets the second loop as well as the third loop, but it didn't detect that there is something wrong with the second loop.
>
> ...Is this a bug ?
C allows you to index one element beyond the end of an array. So, this
uint8_t eightMembers[8];
uint8_t *p = &eightMembers[8];
is legal, but
uint8_t eightMembers[8];
uint8_t *p = &eightMembers[9];
is not.
In both cases you cannot actually use the memory at *p. I think gcc is
detecting the indexing but not the access.
Andrew.