float init 0 request

libxmoc libxmoc at gmail.com
Mon Aug 17 14:16:58 UTC 2026


On Monday, 17 August 2026 at 14:03:46 UTC, Quirin Schroll wrote:
> On Friday, 14 August 2026 at 06:38:02 UTC, Walter Bright wrote:
>> Floats are default initialized to NaN so people will be 
>> coerced to explicitly code what they want the initialized 
>> value to be.
>
> Maybe the next D Edition could require initialization of types 
> that don’t initialize with a value equal to `0`. D’s behavior 
> with these is annoying, because leads to needless debug 
> sessions, and also surprising because no other language that D 
> is similar to does that: C++. C# and Java all 
> default-initialize to `0`. Essentially, character and 
> floating-point types should behave like structs with `@disable 
> this()`.
>
> Of course, as I said, that would be for the next Edition 
> because it would break code. I don’t know how much existing D 
> code really uses those initializers, probably some, but very 
> little, because the defaults are quite useless, intentionally 
> so.

I don't think it's wise to change, it'll cause too much friction 
and inconsistency in documentation, however, I think there is 
something that could be done as a compromise.


extern(C) struct was rejected, so perhaps a `@pod struct` that 
ensures 0 init would be better?

0 init has the advantage of producing tiny executable, so there 
are still some valid reason to have them.


More information about the Digitalmars-d mailing list