Is this really intended??

Paul Backus snarwin at gmail.com
Sun Oct 11 21:58:07 UTC 2020


On Sunday, 11 October 2020 at 21:50:28 UTC, claptrap wrote:
>
> I think the struct should be initialised full stop. I mean 
> whether a member is initialised before the constructor is run 
> shouldn't be dependent on what you do in the constructor. I 
> mean you declare a struct, whether local or as part of an 
> aggregate, it should be default initialised. Its a simple 
> orthogonal rule.

This is how the language already works, at least according to the 
spec:

     When an instance of a struct is created, the following steps 
happen:

         1. The raw data is statically initialized using the 
values provided in
         the struct definition. This operation is equivalent to 
doing a memory
         copy of a static version of the object onto the newly 
allocated one.

         2. If there is a constructor defined for the struct, the 
constructor
         matching the argument list is called.

         3. If struct invariant checking is turned on, the struct 
invariant is
         called at the end of the constructor.


Source: https://dlang.org/spec/struct.html#struct-instantiation


More information about the Digitalmars-d mailing list