RE: type initializers
From: Rick Byers [MSFT] (rbyers_at_online.microsoft.com)
Date: 08/17/04
- Next message: Plausible Indirection: "Re: enumerations as parameters, VB, and the value 0"
- Previous message: Eugene Mayevski: "Re: Socket.BeginReceive without callback?"
- In reply to: George: "type initializers"
- Next in thread: Jim Miller: "Re: type initializers"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 17 Aug 2004 17:07:27 GMT
Hi George,
I'm no expert on the precise language of the CLI standard, but I can see
where there could be some subtle differences between the two descriptions.
(For the reference of others looking at this, it is in partition I section
8.9.5 - bottom of pg. 70 in the annotated standard book).
For example, it is actually possible to create an instance of an object
without calling it's constructor.
System.Runtime.Serialization.FormatterServices.GetUninitializedObject. does
this, which is used during deserialization (eg. BinaryFormatter, not
XmlSerializer).
In general, the standard authors probably prefer being explicit about
intended triggers, than to rely on interactions specified elsewhere that
could change in the future, or be wrong all together. So even if it was
only possible to access a field when a constructor had been called first,
it's probably better not to bake that assumption into the definition of
this behavior.
Rick
-- This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- > > My question is concerning the exact timing when a type initializer is > executed. > > In ECMA, I find the following: > > "If not marked BeforeFieldInit then that type’s initializer method is > executed at (i.e., is triggered > by): > - first access to any static or instance field of that type, or > - first invocation of any static, instance or virtual method of that type" > > Wouldn't be enough to say ONLY the following? > > The type initializer (of a BeforeFieldInit) type is triggered by: > - first access to any static field > - first invocation of any static method or instance constructor of that type > > My reasoning is: > > - if I access an instance field, then I should have already the instance, > right? And if I have the instance, it means I've already invoked an instance > constructor. > - the same for an instance method (or virtual method). > > Am I wrong? Is there something that I miss here? > > Many thanks. > George >
- Next message: Plausible Indirection: "Re: enumerations as parameters, VB, and the value 0"
- Previous message: Eugene Mayevski: "Re: Socket.BeginReceive without callback?"
- In reply to: George: "type initializers"
- Next in thread: Jim Miller: "Re: type initializers"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|