float init 0 request
Walter Bright
newshound2 at digitalmars.com
Fri Aug 14 06:38:02 UTC 2026
Floats are default initialized to NaN so people will be coerced to explicitly
code what they want the initialized value to be.
I've seen enough code where the programmer forgot to initialize a float, it was
defaulted to 0, and the wrong result was not detected.
```d
float f; // code reviewer: did the programmer intend it to be 0?
float g = 0; // code reviewer: yes, the programmer likely meant to initialize it
to 0
```
It's similar to pointers being default initialized to null. Trying to use a null
pointer will result in a seg fault.
Most people decry this, but it's actually a great feature. If there's a bug in
the code, it's better to find it sooner rather than after you ship.
More information about the Digitalmars-d
mailing list