Re: New Implementation of Virtual Functions in C++

landauer@apple.com (Doug Landauer)
19 Nov 1999 22:36:21 -0500

          From comp.compilers

Related articles
New Implementation of Virtual Functions in C++ sjmccaug@prairienet.org (1999-11-18)
Re: New Implementation of Virtual Functions in C++ johnmce@texas.net (1999-11-19)
Re: New Implementation of Virtual Functions in C++ neeri@iis.ee.ethz.ch (Matthias Neeracher) (1999-11-19)
Re: New Implementation of Virtual Functions in C++ landauer@apple.com (1999-11-19)
Re: New Implementation of Virtual Functions in C++ jsgray@acm.org (Jan Gray) (1999-11-23)
| List of all articles for this month |

From: landauer@apple.com (Doug Landauer)
Newsgroups: comp.compilers
Date: 19 Nov 1999 22:36:21 -0500
Organization: Apple Computer, Inc.
References: 99-11-100
Keywords: C++, code

sjmccaug@prairienet.org (Scott J. McCaughrin) wrote:
>
> A colleague informs me that virtual functions are now more commonly
> implemented via thunks (instead of class vtbls).
> [I would be astonished if this were true, regardless of whether he
> means real Algol-style thunks or Microsoft's misnamed function
> wrappers. Every C++ compiler I've ever seen uses vtbls ...]


I suspect that the colleague means C++'s misnamed "this-adjustment
code snippet"s. They are used in conjunction with vtables, not
instead of them. In this case, "thunk" merely means "a bit of code
that's not quite exactly a whole function". In old cfront-style
vtables, every entry had to include a "this-adjustment" to handle
multiple inheritance. Every virtual call had to add in that little
delta, before actually calling the method.


With "-fvtable-thunks" (gcc's name for the now-common style), each
vtable entry is a single address, either an address of the method
itself (in the overwhelming majority of cases, i.e., no MI), or the
address of a "thunk" (in MI cases), which adjusts the "this" pointer
by the right amount, then branches into the actual method. This kind
of vtable is half the size of the other kind, and simple cases (SI) do
not suffer from the existence of the MI language feature, as they did
suffer in the old cfront-style implementation.


I wouldn't venture to guess whether these are "more common" than the
cfront-style vtables yet, since I don't know how MS-VC++ does it :-)
--
        Doug Landauer landauer@apple.com (work)
                                                  landauer@scruznet.com (not-work)



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.