float init 0 request

Serg Gini kornburn at yandex.ru
Wed Aug 19 07:42:00 UTC 2026


On Wednesday, 19 August 2026 at 07:31:14 UTC, Walter Bright wrote:
> On 8/17/2026 7:03 AM, Quirin Schroll wrote:
>> 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`.
>
> My reply to this seems to have disappeared.
>
> C and C++ default initialize locals to garbage, not zero.

C++:
```cpp
float x{};        // x == 0.0f
float y = {};     // y == 0.0f
struct Foo {
   float value{};   // automatically initialized to 0.0f
};
```

> C# and Java give a runtime error if you use locals without 
> explicit initializations.

C#:
```csharp
class Foo
{
     float value;       // automatically 0f
     float[] values = new float[100]; // all 0f
}
```


More information about the Digitalmars-d mailing list