What is the stance on partial initializers when declaring multiple variables of the same type?

Jonathan M Davis jmdavisProg at gmx.com
Fri Jul 22 08:45:56 PDT 2011


On Friday 22 July 2011 15:40:00 Trass3r wrote:
> Am 21.07.2011, 21:55 Uhr, schrieb Andrej Mitrovic
> 
> <andrej.mitrovich at gmail.com>:
> > On 7/21/11, Jacob Carlborg <doob at me.com> wrote:
> >> How about you create a new type, that can be implicitly converted to
> >> float and is initialized to 0.0.
> > 
> > Ha, never thought about that! When I think about it, most of the time
> > I want my floats to be 0-initialized.
> 
> me too!

Well, the idea with default initializers is that they're as close as possible 
to an invalid value (hence NaN for floats) so that it becomes apparent faster 
if you screwed up and didn't initialize them before using them. So, that's why 
floats aren't 0 by default. Integral values wouldn't be 0 either if the 
integral types had something akin to NaN.

- Jonathan M Davis


More information about the Digitalmars-d mailing list