float init 0 request

user1234 user1234 at 12.de
Wed Aug 19 09:33:21 UTC 2026


On Wednesday, 19 August 2026 at 07:42:00 UTC, Serg Gini wrote:
> 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
> }
> ```

I think that your answer is a bit out-of-topic. We started on 
"default init" (implicit value expected) but here you show 
something that's more about "explicit init". That eventually 
falls back on a talk of a D language friend, IIRC, the Salt Lake 
City edition.



More information about the Digitalmars-d mailing list