[RFC] Proper initialization of class members and variables

Michael Pyne michael.pyne at kdemail.net
Sun Nov 20 00:27:07 GMT 2005

On Saturday 19 November 2005 09:14, Luciano Montanaro wrote:
> > Stack and heap POD variables are not auto-initialised to 0 or anything
> > else.
> Yes, but for object instances, the constructor is called.
> If the m_* variables in the patch are member variables, these should be
> initialized in the constructor. If the object does not have an explicit
> constructor, the default one clears the object to zero, if I remember
> correctly. Otherwise the constructor has to initialize the member variables
> itself.

The constructor is called.  But, for plain-old-data member types like all 
pointers, int, bool, etc, no initialization is performed whatsoever unless 
you specifically add it.

For member variables that are of a class, the default constructor will be 
called on it if you do not explicitly call a constructor, so leaving QString 
or other Q* members uninitialized should be "safe" since they will be 
initialized by their default constructor.

That auto-initialization to garbage sounds interesting though, I wonder if we 
could convince the gcc guys to add a debugging switch for it. :)

 - Michael Pyne
-------------- 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/56d969b9/attachment.sig>

More information about the kde-core-devel mailing list