0

the following code does'nt produce any warning when compiled with "-Wall" option in gcc:

int main ()
{
    int c, i;


    for ( ; i < 10; i++ ) {
        c += i;
    }

    return c;
}

This is the command used to build the source:

$ gcc -c -Wall 1.c
$

It returns without any message. I would expect a "warning: ā€˜i’ is used uninitialized in this function", and the same warning for the 'c' variable.

Any idea about this behavior? Thank you.

1 Answers1

0

Analysis performed by -Wall is very limited without optimizations. Warning is successfully detected with -O1 or -O2.

yugr
  • 19,769
  • 3
  • 51
  • 96
  • Thank you! In fact, with -O1 the warnings are correctly signaled. I have been using gcc for years and never noticed it. Good to know!! – Gabriele Brugnoni Sep 22 '22 at 19:50