From: lian <tr...@si...> - 2002-06-10 08:58:36
|
The contents of the paragraph below is C++ code, in which a class CTest inherits the virtual fuction of the struct IUnknown. /////////////////////////////////////////////////////// struct IUnknown { public: virtual int __stdcall QueryInterface( /* [in] */ REFIID riid, /* [iid_is][out] */ void **ppv) = 0; virtual int __stdcall AddRef( void) = 0; virtual int __stdcall Release( void) = 0; }; class CTest: public IUnknown { public: int __stdcall QueryInterface( /* [in] */ REFIID riid, /* [iid_is][out] */ void **ppv); int __stdcall AddRef(void); int __stdcall Release(void); int __stdcall Test(); public : unsigned long RefCnt; }; ////////////////////////////////////////////////////////// My operating system is windows2000, I compiled the code respectively with msvc compiler(cl.exe) and gnu compiler(gcc.exe). After compiling, the binary code of the virtual table as follows: ////////////////////////////////////////////////////////// msvc: CTest virtual table:(size 0x10) 00002010 00 10 40 00 00002020 20 10 40 00 40 10 40 00 e0 10 40 00 e0 10 40 00 ?QueryInterface@CTest@@UAGHABU_tagGUID@@PAPAX@Z: 00401000: 55 push ebp ...... ?AddRef@CTest@@UAGHXZ: 00401020: 55 push ebp ...... ?Release@CTest@@UAGHXZ: 00401040: 55 push ebp ...... ///////////////////////////////////////////////////////////// gnuc: CTest virtual table:(size is 0x18) 00006050 00 00 00 00 6c 57 40 00 14 12 40 00 2c 12 40 00 00006060 44 12 40 00 00 00 00 00 0040576c <___tf5CTest>: // CTest type_info function 40576c: 55 push %ebp ...... 00401214 <_QueryInterface__5CTestRC8_tagGUIDPPv@12>: 401214: 55 push %ebp ...... 0040122c <_AddRef__5CTest@4>: 40122c: 55 push %ebp ...... 00401244 <_Release__5CTest@4>: 401244: 55 push %ebp ...... ////////////////////////////////////////////////////////////// Obviously, the difference between them is that there are 8 bytes more in the result of gcc.exe than that of the cl.exe. That is to say, the virtual table generated by the gcc.exe has two more items. The first item is empty, the second is likely the type_info of the class CTest, the succedent items are identically with the result of cl.exe. My problem is how to eliminate these redundant 8 bytes to make the results of the two compiler to keep compatible in binary code. Thanks a lot ! |