Re: vtable issue

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Thu, 18 Sep 2008 04:46:01 -0700, George
<George@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Two more comments,

1.

In the code below, why there are 3 times of indirection (indirection I mean
get the content pointed to by something, like indirect content access in
C/C++ using pointer), means p-->eax-->edx-->eax, how vtable is organized in
such way... :-)

00411D9D mov eax,dword ptr [p]
00411DA0 mov edx,dword ptr [eax]
00411DA2 mov esi,esp
00411DA4 mov ecx,dword ptr [p]
00411DA7 mov eax,dword ptr [edx]
00411DA9 call eax

2.

Why we need to call mov ecx,dword ptr [p], I find it is not very useful here.

IIRC, ecx holds the "this" pointer when calling a non-static member
function. See __thiscall for more.

These articles may help you decipher assembly:

http://www.microsoft.com/msj/0298/hood0298.aspx
http://www.microsoft.com/msj/0698/hood0698.aspx

If you get any deeper into how the compiler implements vtbls and whatnot,
see:

http://www.openrce.org/articles/files/jangrayhood.pdf

The last one used to be on MSDN, but I can't find it right now.

--
Doug Harrison
Visual C++ MVP
.



Relevant Pages