This is the mail archive of the
mailing list for the GCC project.
Re: Missing warning about uninitialized variable.
- From: John Love-Jensen <eljay at adobe dot com>
- To: "J.C. Pizarro" <jcpiza at gmail dot com>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Thu, 29 Nov 2007 10:58:33 -0600
- Subject: Re: Missing warning about uninitialized variable.
> Yes eschenb, they are 11 args, but i've found a weird thing.
> With -O, -O1, -O2, -O3, they print 5 times of value 3 (when argc == 11)
> Without optimization, it prints stochasticly random data (when argc == 11).
That is not a weird thing. And it is unlikely that the non-optimized case
the data is actually stochastically random -- more likely there is a reason
it is the value it has. For instance (pure speculation), the value may be a
left-over stack value for the PID. In that the value isn't the same from
run-to-run could be a factor of the PID not being identical from run-to-run.
> Why is it false positive to say it prints 3 when it should print
> random data instead of 3 because argc != 10?
Uninitialized data is not the same thing as random data.
> There is some strange in the generated program.
No, consistently valued uninitialized data is not strange, especially for an
optimized program. In the optimized program case, the previous "random"
value may still be present, but the location of the variable in stack memory
may have been optimized to a different location, which now has a
consistently valued uninitialized value.
> For large projects with uninitialized variables, the behaviour
> could be stochasticly flawed as a russian roulette.
Uninitialized variables is, in my opinion, a serious shortcoming in C and
In my opinion, the DEFAULT behavior should be initialized to some known
value that can be relied upon, and extra measures should need to be taken to
tell the compiler NOT to initialize the variable.
That's all well and good, but it's not C or C++.
Adding that to C or C++ would make a variant language that
is-close-to-but-not-quite the standard language.
I've tried my hand at making my own general purpose language, and have given
up. I think to do a good job would require many years of focused
dedication, and I just don't have the patience. Fortunately, Walter Bright
does have the stamina and wherewithal, and created the D Programming
Language which implements 90%+ of the way I envisioned my aborted attempt,
and then some! My only minor complaints are C++-esque "const correctness",
C++-esque I/O streams, and "wish it had overloading". Kudos, Walter Bright!