RE: ECMA Wrong - Class and Object Initialization Rules - Help!
- From: George <George@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 14 Apr 2005 01:22:01 -0700
Hi J.V.,
thank you for the answer.
Unfortunately, I do not get your point.
> An instance of a class can be created only if the constructor of the class'
> base class is invoked. In your example, class A is a stand-alone class and
> hence, in the object creation cycle the base Object class is sought for
> object construction and hence, the this pointer is initialized.
In my example, the .ctor of Object is not invoked at all - so, strictly
according to ECMA, the this pointer in an A .ctor should *not* be considered
initialized.
Here is the example:
the class A extends Object
here is a .ctor of A which takes two arguments:
.method public hidebysig specialname rtspecialname
instance void .ctor(int32 i,
int32 j) cil managed
{
.maxstack 3
.locals init (class A V_0)
ldarg 0
ldarg.1
ldarg.2
add
call instance void A::.ctor(int32)
ldarg 0
stloc 0
ret
} // end of method A::.ctor
here is the second .ctor of A which takes only one argument:
..method public hidebysig specialname rtspecialname
instance void .ctor(int32 i) cil managed
{
.maxstack 4
ldarg.0
ldarg.1
ldarg.1
call instance void A::.ctor(int32,int32)
ret
} // end of method A::.ctor
As you see, the two .ctor-s invoke each other. In the first one, we store
the "this" pointer into a local variable and the verifier does not complain.
This can happen only because the "this" pointer is considered initialized. If
we move the two instructions "ldarg 0, stloc 0" at the beginning of the
..ctor, then th example is rejected by the verifier since the "this" is not
initialized.
Hence, the invocation of a .ctor of the same class determines the "this"
pointer of the current .ctor to be considered initialized.
There is no invocation of the base .ctor, i.e. ctor of Object!
Best regards,
George
.
- References:
- ECMA Wrong - Class and Object Initialization Rules - Help!
- From: George
- RE: ECMA Wrong - Class and Object Initialization Rules - Help!
- From: Ravichandran J.V.
- ECMA Wrong - Class and Object Initialization Rules - Help!
- Prev by Date: RE: Simple Question (regarding runtime)
- Next by Date: RE: ECMA Wrong - Class and Object Initialization Rules - Help!
- Previous by thread: RE: ECMA Wrong - Class and Object Initialization Rules - Help!
- Next by thread: RE: ECMA Wrong - Class and Object Initialization Rules - Help!
- Index(es):
Relevant Pages
|