Static constructors guaranteed to run?
Tofu Ninja via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jun 28 20:10:44 PDT 2015
On Monday, 29 June 2015 at 02:31:18 UTC, ketmar wrote:
> yes. it doesn't do that now, afair, but i can't see any sense
> in running code that obviously does nothing, as it's owner is
> not used. module ctors was designed for such things -- i.e. to
> run some code on startup. if someone is doing some vital
> initialization in static ctor of struct or class, and that
> struct or class aren't used anywhere else in his code, he's
> doing it wrong. it *may* work now, but that's simply 'cause
> compiler is not very well at removing unused code.
That seems wrong, what if I am doing separate compilation, how
would the compiler know if the type is going to be used or not...
More information about the Digitalmars-d-learn
mailing list