-Wall not detecting uninitialized variables

Axel Freyn axel-freyn@gmx.de
Wed Sep 7 16:44:00 GMT 2011


On Wed, Sep 07, 2011 at 05:36:50PM +0100, Andrew Haley wrote:
> On 09/07/2011 05:34 PM, sudhakar govindavajhala wrote:
> > #include <stdio.h>
> > 
> > int main() {
> >         int i;
> >         printf(" hi sud %d \n", i);
> >         return 0;
> > 
> > }
> 
> zebedee:~ $ gcc --version
> gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
> 
> zebedee:~ $ gcc -Wall t.c
> t.c: In function 'main':
> t.c:5:15: warning: 'i' is used uninitialized in this function

gcc 4.1 warns if optimization is activated:
Jupiter:~ $ gcc-4.1 -Wall -O test.c
test.c: In function ‘main’:
test.c:5: warning: ‘i’ is used uninitialized in this function

Jupiter:~ $ gcc-4.1 --version
gcc-4.1 (GCC) 4.1.3 20080704 (prerelease) (Debian 4.1.2-29)

Axel



More information about the Gcc-help mailing list