This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Missing warning about uninitialized variable.


On 2007/11/29, Mikael Vidstedt <mikael.vidstedt@bea.com> wrote:
> 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

It prints stochasticly random data too.

gcc version 4.2.3 20071031 (prerelease)

$ gcc -Wall -o foo foo.c
foo.c: In function 'main':
foo.c:11: warning: implicit declaration of function 'printf'
foo.c:11: warning: incompatible implicit declaration of built-in
function 'printf'
$ for i in $(seq 1 5); do ./foo $(seq 1 10) ; done
-1209020420
-1208291332
-1208422404
-1208803332
-1208823812
$

   J.C.Pizarro


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]