[Mono-devel-list] Static fields initialization

Ben Maurer bmaurer at ximian.com
Thu Nov 4 15:42:34 EST 2004

On Thu, 2004-11-04 at 20:48 +0100, mono at evain.net wrote:
> Using Mono runtime, the output is 2, but with MS, it is 0.
> If I found that Mono's behaviour is much more logical, here is a quote from 
> the ECMA CLI Standard (line 14, page 85): 
> "The <fieldInit> information is stored in metadata and this information can 
> be queried from metadata.  But the CLI does not use this information to 
> automatically initialize the corresponding fields." 
> And here is a quote from Inside MS.NET IL Assembler : 
> "What will the value of the field be when the class is loaded? Correct 
> answer: 0. Why? Because default values specified in the Constant table are 
> not used by the loader to initialize the items to which they are assigned. 
> If we want to initialize a field to its default value, we must explicitly 
> call the respective Reflection method to retrieve the value from metadata 
> and then store this value in the field. This doesn't sound too nice, but, on 
> the other hand, we should not forget that these are default values rather 
> than initial values, so formally the loader might be right." 
> I've already told that I do prefer Mono's behaviour here, but I would like 
> to have some guru's opinions about this. 

This was probably from when we had allocated room for literal fields in
the static data area. But we don't do this any more. We can safely
remove the behavior.

The ECMA spec is final here...

Ben Maurer <bmaurer at ximian.com>

More information about the Mono-devel-list mailing list