Hi list. I think I've found a bug in where gcc checks if array indices are in range.
Here's my test-code: ---8<-----8<-----8<----- /* * file: elementTest.c * command-line: * arm-none-eabi-gcc -O2 elementTest.c -o elementTest */ #include <stdint.h> uint8_t eightMembers[8]; int main(int argc, const char *argv[]) { uint8_t i; for(i = 0; i < 8; i++) { eightMembers[i] = 0; } for(i = 0; i < 9; i++) { eightMembers[i] = 0; } for(i = 0; i < 10; i++) { eightMembers[i] = 0; } return(0); } --->8----->8----->8----- Here's my result: ---8<-----8<-----8<----- elementTest.c: In function 'main': elementTest.c:27:19: warning: iteration 8u invokes undefined behavior [-Waggressive-loop-optimizations] eightMembers[i] = 0; ^ elementTest.c:25:2: note: containing loop for(i = 0; i < 10; i++) ^ --->8----->8----->8----- 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 ? Love Jens