Topic: implementation or virtual functions
Author: comeau@panix.com (Greg Comeau)
Date: 1999/06/02 Raw View
In article <374F1AE3.1E0EE9ED@spots.ab.ca> fysx <fysx@spots.ab.ca> writes:
> Does the C++ definition state that classes containing virtual
>functions must have a virtual function table pointer?
Only the behavior of the dynamic binding is described.
>or can the
>implementation of virtual functions be left to the compiler to decide?
>ie. alternatives for dynamic binding other then virtual function tables.
The language supports the notion of vptrs and vtables in various places,
but it in no way constrains it to that. They are strictly implementation
details, albeit a common ones since they are the most reasonable approach
in many cases.
As a general rule of thumb, consider the machinery of a feature
(virtual functions, virtual inheritance, static initialization, etc)
as an implementation detail.
- Greg
--
Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418-3214
Producers of Comeau C/C++ 4.2.38 -- New Release! We now do Windows too.
Email: comeau@comeaucomputing.com / Voice:718-945-0009 / Fax:718-441-2310
*** WEB: http://www.comeaucomputing.com ***
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: fysx <fysx@spots.ab.ca>
Date: 1999/05/30 Raw View
Hi,
Does the C++ definition state that classes containing virtual
functions must have a virtual function table pointer? or can the
implementation of virtual functions be left to the compiler to decide?
ie. alternatives for dynamic binding other then virtual function tables.
fysx
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: jcoffin@taeus.com (Jerry Coffin)
Date: 1999/05/30 Raw View
In article <374F1AE3.1E0EE9ED@spots.ab.ca>, fysx@spots.ab.ca says...
> Hi,
> Does the C++ definition state that classes containing virtual
> functions must have a virtual function table pointer? or can the
> implementation of virtual functions be left to the compiler to decide?
> ie. alternatives for dynamic binding other then virtual function tables.
The standard describes how virtual functions must behave, but not how
they must be implemented. A vtable per class, and a pointer per
object seems to be one of the most efficient methods presently known,
but there's nothing (in the standard) preventing other methods.
Just for example, if you were doing an implementation for MS-DOS, you
might decide to create a single table of vtables, and then put a index
into the master table in each object. This would typically result in
a slight speed loss (due to an extra level of indirection), but might
result in significant space savings; you could probably use a single
byte (or perhaps two bytes) for the index, instead of the 4 bytes for
a "far" pointer.
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1999/05/31 Raw View
fysx wrote:
>
> Hi,
> Does the C++ definition state that classes containing virtual
> functions must have a virtual function table pointer? or can the
> implementation of virtual functions be left to the compiler to decide?
> ie. alternatives for dynamic binding other then virtual function tables.
The C++ standard makes absolutely no mention of virtual function table
pointers. They are merely a fairly common implementation technique.
Portable code should make no assumptions based upon the idea that one
exists.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: clamage@eng.sun.com (Steve Clamage)
Date: 1999/05/31 Raw View
fysx <fysx@spots.ab.ca> writes:
> Does the C++ definition state that classes containing virtual
>functions must have a virtual function table pointer? or can the
>implementation of virtual functions be left to the compiler to decide?
>ie. alternatives for dynamic binding other then virtual function tables.
The C++ standard defines only the behavior of dynamic binding.
It makes no requirements whatever on how virtual functions
are implemented.
The simplest and most efficient mechanisms yet known are based on
tables of function addresses which polymorphic objects point to.
Details of such vtables vary considerably among implementations,
however.
--
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]