using .init reliably
Johan Engelen via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Aug 26 04:20:56 PDT 2016
On Friday, 26 August 2016 at 09:48:00 UTC, Jonathan M Davis wrote:
>
> You're supposed to be able to depend on .init existing. Default
> initialization for structs can be disabled via
>
> @disable this();
>
> but even then, the init member still exists (it just isn't used
> for default initialization).
From what I remember, the last time I looked at `@disable
this();`:
it prevents the user from creating a default initialized struct.
However whenever (compiler internally) the struct needs
initialization, `.init` is still used. And thus it is also used
at the start of any constructor the user writes.
Don't take my word for it: have a look at asm output, or easier:
LCD's LLVM IR output.
-Johan
More information about the Digitalmars-d-learn
mailing list