[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What should the call stack look like when calling a C++ virtual func
From: |
Paul Pluzhnikov |
Subject: |
Re: What should the call stack look like when calling a C++ virtual function? |
Date: |
Sat, 23 Sep 2006 17:17:15 -0700 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux) |
"Dev1024" <lmemmott@yahoo.com> writes:
> Having been a long time user of Microsoft Visual C++ .Net 2003 (MSVC),
> I've recently been using g++ on a project. I've found a difference
> between the two compilers when calling a virtual function that has me
> puzzled.
The immediate question is "why do you care?"
> The issue is when calling virtual functions. In MSVC the parameters
> are pushed on to the stack as expected and then the address of the
> function is loaded into EAX. Finally "call EAX" is issues to call the
> virtual function.
That is incorrect: you are missing a step: loading "this" into %esi.
> In g++ (Cygwin g++ v3.4.4) the parameters are pushed
> onto the stack as expected, but then a pointer (32 bit pointer in my
> case) to the vtable is pushed on the stack as well
That is also incorrect: it's the "this" parameter that is pushed.
However, since g++ puts the vtable at the start of any class with
virtual functions, the "this" and &vtbl are the same thing.
> - Why does g++ load a pointer to the vtable on the stack after pushing
> on the params?
It doesn't. It simply passes all parameters (including "this")
on the stack.
> - Is there a compiler option that can be used to avoid putting a
> pointer to the vtable on the stack? (I looked but couldn't find one.)
These are implementation details, best left alone.
Are you trying to link together MSVC and g++ compiled code?
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
- What should the call stack look like when calling a C++ virtual function?, Dev1024, 2006/09/23
- Re: What should the call stack look like when calling a C++ virtual function?,
Paul Pluzhnikov <=
- Re: What should the call stack look like when calling a C++ virtual function?, Dev1024, 2006/09/24
- Re: What should the call stack look like when calling a C++ virtual function?, Paul Pluzhnikov, 2006/09/25
- Re: What should the call stack look like when calling a C++ virtual function?, Dev1024, 2006/09/25
- Re: What should the call stack look like when calling a C++ virtual function?, Paul Pluzhnikov, 2006/09/25
- Re: What should the call stack look like when calling a C++ virtual function?, Dev1024, 2006/09/25
- Re: What should the call stack look like when calling a C++ virtual function?, Dev1024, 2006/09/25
- Re: What should the call stack look like when calling a C++ virtual function?, Dev1024, 2006/09/27
- Re: What should the call stack look like when calling a C++ virtual function?, Paul Pluzhnikov, 2006/09/28