[RFC] Proper initialization of class members and variables

Thiago Macieira thiago at kde.org
Sat Nov 19 11:59:46 GMT 2005

Christian Ehrlicher wrote:
>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.
>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).

Stack and heap POD variables are not auto-initialised to 0 or anything 

To rely on them being so is an error and they must be flushed out.

The difference here is the memory allocator. Apparently, operator new on 
Linux returns newly-allocated pages from the OS more frequently (those 
are initialised to 0 by the OS). 

I find it difficult to believe Windows would give one program's page to 
another without zeroing it out first.

  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

4. And æfter se scieppend ingelogode, he wrát "cenn", ac eala! se 
rihtendgesamnung andswarode "cenn: ne wát hú cennan 'eall'. Ástynt."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20051119/b5fd7bd7/attachment.sig>

More information about the kde-core-devel mailing list