[prog] [C] strings bug
kjh at flyballdogs.com
Thu Apr 10 09:39:38 EST 2003
> Well, I have less exalted sources to refer to, but I remember being taught
> that with C++, unlike C, uninitialised variables were initialised to zero
> by default, but that it was still bad style to rely on that feature.
> Indeed, I prefer Java's attitude - "this variable may be used unassigned"
> is a build-stopping error. If you're going to use a variable initialised
> to zero, fine, but do it explicitly.
For POD types, C++ provides exactly the same semantics as C++, variables
in the global namespace will be initialized to 0. For non-POD types, C++
will call the constructor for objects in the global namespace before any
code in the same source file is executed. Automatic POD variables are not
initialized by default and constructors are not required to initialize
So it may be that whomever gave you that advice was either mistaken or
talking about the context of a specific class with constructors that
initialized all members.
More information about the Programming