order of static constructor execution

BCS none at anon.com
Fri Mar 12 12:57:25 PST 2010


Hello Walter,

> Doing lazy initialization certainly works, but it would require all
> static member access to go through a check for initialization, first.
> The cost of this check persists for a statically compiled language;
> for a JITted language like C# the access can be rewritten to remove
> the check.

That and I have some patterns I like using where I use "static this()" to 
inject results without any change to the code base. For that to work, they 
need to run before things get referenced.

void delegate(string)[string] args; // static this injects into here.

void main(string[] argv)
{
    foreach(string s; argv)
         args[GetBefor('=',s)](GetAfter('=',s));
}

-- 
... <IXOYE><






More information about the Digitalmars-d mailing list