float init 0 request

Walter Bright newshound2 at digitalmars.com
Tue Aug 18 03:25:37 UTC 2026


On 8/17/2026 12:47 AM, pete wrote:
> There is something I don't understand here. If an uninitialised float is an 
> error then why does the compiler not just raise it at compile time rather than 
> setting it to a value that is always wrong and letting someone *hopefully* find 
> it at runtime?

Because of code like this:

```d
float f;
if (...)
     f = 1;
else
     f = 2;
```

If the compiler gave an error for no initializer, the code will look like:


```d
float f = 0; // shut up vacuous diagnostic message
if (...)
     f = 1;
else
     f = 2;
```

which is inelegant.

Real cases of this tend to be more complex, which leaves the code reviewer with 
the task of determining why f is explicitly set to 0 when 0 is not the right 
value for f.


More information about the Digitalmars-d mailing list