[RFC] Proper initialization of class members and variables

André Wöbbeking Woebbeking at onlinehome.de
Sat Nov 19 11:02:47 GMT 2005

On Saturday 19 November 2005 11:11, Christian Ehrlicher wrote:
> Hi,
> I get a lot of trouble because of unitialised variables when using
> msvc. This is because gcc seems to auto-initialize all vars with '0'
> but msvc does not (in debug it fills all with 0xcd).
> My question is if autoinitialization is a c++-standard (and msvc
> ignores it) or if this is a gcc feature.

No, the opposite. To be as fast as C PODs aren't auto initialized. And 
it isn't a GCC feature neither. If you don't initialize a POD its value 
isn't defined. But very often it's 0 but it doesn't have to. 

valgrind is your friend to find the places where not initialized 
variables/memory are used.

> If this is a gcc feature, you should avoid it and initialize all
> variables before use because you never know how other compilers
> initialize the memory (and imho it's not a good coding style to not
> initialize variables before use).

You're absolutely right.


More information about the kde-core-devel mailing list