[comp.lang.c++] vtable sharing in cfront

mnm@hpclove.HP.COM (Michey Mehta) (09/02/89)

I recently took a C++ course at UC Santa Cruz which was taught by
Stroustrup.  During this course, he mentioned that if a class needs a
virtual function table, this table is defined in only one file (this
is the file which contains the definition of the first virtual member
function); all other files will just have an extern declaration of
this vtable.  This is a new feature of 2.0.  I have two questions
about this:

1. He also mentioned a corner case in which multiple vtable
   definitions might still be emitted for the same class; does anyone
   know what this corner case is?

2. In light of this feature, what do the +e0 and +e1 options do
   in 2.0?

--
Michey Mehta  -- Hewlett Packard California Language Lab
Internet: mnm@hpda.hp.com          UUCP: hplabs!hpda!mnm

ark@alice.UUCP (Andrew Koenig) (09/11/89)

In article <1250003@hpclove.HP.COM>, mnm@hpclove.HP.COM (Michey Mehta) writes:

> I recently took a C++ course at UC Santa Cruz which was taught by
> Stroustrup.  During this course, he mentioned that if a class needs a
> virtual function table, this table is defined in only one file (this
> is the file which contains the definition of the first virtual member
> function); all other files will just have an extern declaration of
> this vtable.

> 1. He also mentioned a corner case in which multiple vtable
>    definitions might still be emitted for the same class; does anyone
>    know what this corner case is?

Cfront 2.0 lays down the definition of the vtable in the compilation
that contains the definition (not declaration) of the first function
in the class that is virtual and not inline.  If there is no such function,
multiple vtable definitions might still be emitted.  For example,
a class all of whose virtual functions are inline.

This is a slight oversimplification.  Another case is a class whose first
virtual function is inline but is not declared inline until later:

	class X {
	public:
		virtual void f();
	};

	inline void X::f() { }

> 2. In light of this feature, what do the +e0 and +e1 options do
>    in 2.0?

They control placement of vtables for the cases where cfront cannot
confidently figure out what to do unassisted.
-- 
				--Andrew Koenig
				  ark@europa.att.com