[Mono-list] ikvm and Mono 0.20
Thu, 27 Feb 2003 03:10:12 +0200
> There is already a flag in the type that relaxes the restrictions,
> though it's not set by the compiler by default (beforefieldinit).
CSC behaves like this: if there is explicit static ctor in the source code
then it omits beforefieldinit, so type initializer must execute .cctor before
any static method is called or any static field is referenced. In other words
it calls .cctor on type load.
But if you have compiler-generated .cctor (i.e. you just have a bunch of
assignments to static members in your code), then CSC inserts beforefieldinit,
and .cctor will be called in a lazy fashion on the first access to the type's static
There is a rationale for this in the specs: calling all .cctors at load type could be
expensive, most .cctors are just a bunch of assignments to static fields, compiler
generated cctor is guaranted to be such a bunch of assignments so it's okay to
delay initialization, while user-defined static ctor may contain some complex code
so it's important to ensure static initilization guarantee.
It's optimization and not a requirement, but I thought it was implemented in MCS, no?