RE: ECMA Wrong - Class and Object Initialization Rules - Help!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • Re: Problem with class type in static instance of struct
    ... > and perhaps even a default constructor). ... In your case where you have the small string ... > support, the pointer is copied, but it points to the array of a temporary ... the class does have a default ctor, several other ctors, a copy ctor and a ...
    (comp.lang.cpp)
  • Re: vector problem
    ... I also use the vector to get a pointer to each of the ... constructor is called more times than the once. ... To control reallocation, use vector::reserve. ... the compiler will generate a suitable copy ctor for you in this ...
    (microsoft.public.vc.mfc)
  • Re: vector problem
    ... I also use the vector to get a pointer to each of the ... constructor is called more times than the once. ... To control reallocation, use vector::reserve. ... the compiler will generate a suitable copy ctor for you in this ...
    (microsoft.public.vc.mfc)
  • Re: The difference between 0 and NULL?
    ... I noticed there existed only one ctor for the class and it was ... It's a no argument ctor that initializes 3 variables in ... I noticed that the pointer was being ... Perhaps your first compile was bad ...
    (comp.unix.programmer)
  • Re: The difference between 0 and NULL?
    ... > program (the calls to printf() notwithstanding) and ModemObject is a ... I noticed there existed only one ctor for the class and it was ... It's a no argument ctor that initializes 3 variables in ... I noticed that the pointer was being ...
    (comp.unix.programmer)