float init 0 request

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Mon Aug 17 14:15:54 UTC 2026


On 18/08/2026 2:03 AM, 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.

Just keep in mind that this cannot cover all cases, like heap allocations.



More information about the Digitalmars-d mailing list