Hacker News new | past | comments | ask | show | jobs | submit login

Perhaps that is inexcusable. GNU gcc version 13.2.0 (with -O2, as documented) does report a problem.

    $ cat tst.c
    int main () {
      int x[10];
      return *(x+20);
    }
    $ gcc -Wall -O2 tst.c
    tst.c: In function ‘main’:
    tst.c:3:10: warning: array subscript 20 is outside array bounds of ‘int[10]’ [-Warray-bounds=]
        3 |   return *(x+20);
          |          ^~~~~~~
    tst.c:2:7: note: at offset 80 into object ‘x’ of size 40
        2 |   int x[10];
          |       ^



These are easy mode arrays, with size and offset known at compile time. Receiving x as an int* parameter to a function, with no way to know its length automatically, would be more realistic.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: