Re: Uninitialized values?
On Apr 20, 11:54 pm, Jack Klein <jackkl...@spamcop.net> wrote:
On Sun, 20 Apr 2008 10:49:55 -0400, Ron Natalie <r...@spamcop.net>
wrote in comp.lang.c++:
red floyd wrote:
howa wrote:
What are the default value for initialized variable?
e.g.
int d; // debug give me -858993460
char c; // debug give me -52
I am using VS.net 2005
It's either unspecified or implementation defined.
However, in the case of VS, it's all cc's.
The word the standard uses is INDETERMINATE.
It's a gross piece of insanity left over from historical C
stupidity that certain types neglect to perform their
default initialization at times (the default initialization
of int and char is to zero initialize them by the way).
The above disclaimer must be understood as representing the
view of some, but by no means all, C++ programmers.
I think it pretty much sums up the only reasonable attitude for
a professional programmer to have.
One of the stated purposes in the development of the C++
language was to keep the efficiency that makes C so valuable
for system programming. Adding extra overhead of initializing
local variables without directions from the programmer adds
code size and execution time.
How much extra overhead does it really have? Have you measured
it? Most of the time, if you do actually initialize the
variable before use, the compiler will see it, and not bother
with any other initialization.
When you consider the fact that one of the first features that
C++ added to C was the ability to define local objects at any
point in a block, making it possible to defer definition until
you know what you want to initialize it with, the complaint
above is can be seen in a different context.
The author wants to add baggage to the language to protect
programmers from coding errors.
The author wants to make program behavior reproduceable, so that
a test means something. If you don't believe in testing code,
and don't mind random behavior, there's no problem. Otherwise,
there is.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34