How to check border in gcc / mingw?

Having tried it

int main (void) {

int a [10]; and [20] = 5;

}

gcc -wall -O2 main.c

This does not give me a warning ...

This is gcc in windows (mingw), and I cannot detect this border restriction error

how to tell the compiler to check it? can it do that?

thank

+3
source share
3 answers

There are attempts to cope with checking the boundaries of the array. By default, the santdard C99 says nothing about applying array boundaries, I suppose, mainly because it has more overhead.

So you can look at sites like these, where people tried to deal with this:

http://williambader.com/bounds/example.html

+2

, , , . SO . , , .

+1

, , , . , gcc, clang (, ). .

, 4, 4:

    ex9.c:17:2: warning: array index 4 is past the end of the array (which contains
          4 elements) [-Warray-bounds]
            numbers[4] = 4;
            ^       ~
    ex9.c:4:2: note: array 'numbers' declared here
            int numbers[4] = {0};
            ^

Kajal

+1

Source: https://habr.com/ru/post/1749397/


All Articles