Static constructors guaranteed to run?

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 1 02:42:31 PDT 2015


On Wednesday, 1 July 2015 at 07:55:20 UTC, ketmar wrote:
> On Mon, 29 Jun 2015 17:22:17 +0000, Marc Schütz wrote:
>
>> On Monday, 29 June 2015 at 11:36:42 UTC, ketmar wrote:
>>> it doesn't, afair, but it's quite natural. if user type was 
>>> throwed out as unused, it would be very strange to insist on 
>>> keeping it's initialization code.
>> 
>> Yes, but I would instead expect that the static ctor prevents 
>> the type from becoming unused in the first place.
>
> and i expect it to be thrown away. ;-) as we have module-scope 
> static ctors to initialize various things that should be always 
> initialized. and type static ctor -- by my logic deduction -- 
> should only initialize internal type fields. and why should i 
> even bother to initialize that internal fields if the type is 
> not used anywhere?

The behaviour you expect makes more sense, for sure, but I was 
trying to guess what the current implementation might be doing 
without actually having to try it :-)


More information about the Digitalmars-d-learn mailing list