float init 0 request
Valentino Giudice
valentino.giudice96 at gmail.com
Mon Aug 24 03:16:29 UTC 2026
On Friday, 14 August 2026 at 05:57:55 UTC, ABrightLight wrote:
> Hello. I understand this subject's been discussed a number of
> times before, but I'd like to throw in my reasoning for why it
> would benefit us more for floats to initialize to 0 than NaN.
I second the request for initializing floats to 0.
Simply being able to declare array or variables wouldn't require
the standard to guarantee any default value for anything.
In fact, it is possible, in D, to declare an array without
initializing it. This could be the default, but it isn't, meaning
the user can rely on arrays initialized by default. This isn't my
style, but it is allowed by the language and it is justified by
the fact that it is possible to create an array which is
initialized by default or not.
All other types are initialized to the most useful values. For
integers that is usually 0. For pointers and references that is
clearly null. There is no valid pointer that could be used and
null is the only invalid pointer that can be checked for and it
safely indicates that no object is being referenced.
Because null is 0, arrays can be trivially initialized with a
calloc at a lower level.
I don't see why all other types are initialized to the most
useful value, but floats are initialized to the most useless one.
If the goal were to force users to initialize everything
manually, than no default initialization should be guaranteed at
all, but it is. Void initialization and uninitializedArray
wouldn't exist, as they would simply represent the default
behavior.
More information about the Digitalmars-d
mailing list