Missing warning about uninitialized variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The following program may make use of an uninitialized variable (gurka):

int
main(int argc, char* argv[])
{
   int gurka;

   if(argc == 10) {
      gurka = 3;
   }

   // gurka isn't necessarily initialized here...
   printf("%d\n", gurka);

   return 0;
}

GCC 4.0 will give a warning when this program is compiled with "-O
-Wall". GCC 4.1 and 4.2 do not give that warning. I haven't had the
possibility to try GCC 4.3.

What say ye?

Thanks,
Mikael


# gcc-4.0 --version
gcc-4.0 (GCC) 4.0.4 20060904 (prerelease) (Debian 4.0.3-7)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

# gcc-4.0 -O -Wall -o foo foo.c
foo.c: In function 'main':
foo.c:6: warning: 'gurka' may be used uninitialized in this function
#


# gcc-4.1 --version
gcc-4.1 (GCC) 4.1.3 20071019 (prerelease) (Debian 4.1.2-17)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

# gcc-4.1 -O -Wall -o foo foo.c
#


# gcc-4.2 --version
gcc-4.2 (GCC) 4.2.3 20071014 (prerelease) (Debian 4.2.2-3)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

# gcc-4.2 -O -Wall -o foo foo.c
#


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux