I am kind of confused by one question: Under what cirumstances does the MS VC++ compiler generate a this adjustor? Notice that the this adjustor is not necessarily in a thunk. Below is my test code.
class myIUnknown
{
public:
virtual void IUnknown_method1(void)=0;
virtual void IUnknown_method2(void)=0;
int data_unknown_1;
int data_unknown_2;
};
class BaseX:public myIUnknown
{
public:
BaseX(int);
virtual void base_x_method1(void)=0;
virtual void base_x_method2(void)=0;
int data_base_x;
int data_unknown_1;
int data_unknown_2;
};
class BaseY:public myIUnknown
{
public:
BaseY(int);
virtual void base_y_method1(void);
virtual void base_y_method2(void)=0;
int data_base_y;
int data_unknown_1;
int data_unknown_2;
};
class ClassA:public BaseX, public BaseY
{
public:
ClassA(void);
//myIUnknown
void IUnknown_method1(void);
void IUnknown_method2(void);
//baseX
void base_x_method1(void) ;
void base_x_method2(void) ;
//baseY
//void base_y_method1(void) ;
void base_y_method2(void) ;
virtual void class_a_method(void);
int data_class_a;
int data_unknown_1;
int data_unknown_2;
};
The object layout is as below:
1> class ClassA size(60):
1> +---
1> | +--- (base class BaseX)
1> | | +--- (base class myIUnknown)
1> 0 | | | {vfptr}
1> 4 | | | data_unknown_1
1> 8 | | | data_unknown_2
1> | | +---
1> 12 | | data_base_x
1> 16 | | data_unknown_1
1> 20 | | data_unknown_2
1> | +---
1> | +--- (base class BaseY)
1> | | +--- (base class myIUnknown)
1> 24 | | | {vfptr}
1> 28 | | | data_unknown_1
1> 32 | | | data_unknown_2
1> | | +---
1> 36 | | data_base_y
1> 40 | | data_unknown_1
1> 44 | | data_unknown_2
1> | +---
1> 48 | data_class_a
1> 52 | data_unknown_1
1> 56 | data_unknown_2
1> +---
1>
1> ClassA::$vftable@BaseX@:
1> | &ClassA_meta
1> | 0
1> 0 | &ClassA::IUnknown_method1
1> 1 | &ClassA::IUnknown_method2
1> 2 | &ClassA::base_x_method1
1> 3 | &ClassA::base_x_method2
1> 4 | &ClassA::class_a_method
1>
1> ClassA::$vftable@BaseY@:
1> | -24
1> 0 | &thunk: this-=24; goto ClassA::IUnknown_method1 <=====in-thunk "this adjustor"
1> 1 | &thunk: this-=24; goto ClassA::IUnknown_method2 <=====in-thunk "this adjustor"
1> 2 | &BaseY::base_y_method1
1> 3 | &ClassA::base_y_method2
1>
1> ClassA::IUnknown_method1 this adjustor: 0
1> ClassA::IUnknown_method2 this adjustor: 0
1> ClassA::base_x_method1 this adjustor: 0
1> ClassA::base_x_method2 this adjustor: 0
1> ClassA::base_y_method2 this adjustor: 24 <============non-in-thunk "this adjustor"
1> ClassA::class_a_method this adjustor: 0
And I found that in the following invokation, this pointer adjustors is generated:
in-thunk this adjustor:
pY->IUnknown_method1();//adjustor this! this-=24 pY-24==>pA
pY->IUnknown_method2();//adjustor this! this-=24 pY-24==>pA
non-in-thunk this adjustor:
pA->base_y_method2();//adjustor this! this+=24 pA+24==>pY
Could anyone tell me why the compiler produce this adjustor in the above invocations?
Under what cirumstances will the compiler generate the this adjustor?
Many thanks.