Re: Q: Optimising out C++ RTTI

David L Moore <>
28 Dec 1996 21:08:16 -0500

          From comp.compilers

Related articles
Q: Optimising out C++ RTTI (Nor Jaidi) (1996-12-27)
Re: Q: Optimising out C++ RTTI (1996-12-28)
Re: Q: Optimising out C++ RTTI (David L Moore) (1996-12-28)
Re: Q: Optimising out C++ RTTI (Julian Dolby) (1997-01-02)
| List of all articles for this month |

From: David L Moore <>
Newsgroups: comp.compilers
Date: 28 Dec 1996 21:08:16 -0500
Organization: Netcom
References: 96-12-179
Keywords: C++, optimize

Nor Jaidi wrote:
> Being a curiousity-proof cat, I have been doing some thinking about
> C++ RTTI and came to the conclusion that it is something you have to
> pay even if you don't use it. May be I am wrong. Are there any
> compiler tricks that optimise out RTTI when not used?

As I read the (draft) standard, RTTI is "free" in that you can only
tell the concrete type of an object that contains virtual
functions. If the pointer you use points to something that contains no
virtual functions, you get the putative type of the pointer.

EG. In this case:

class A { int i; };
class B: public A { virtual x(); };
A * x = NEW b;

The the typeof(x) is A, not B.

As a result, you do not have to add a dispatch table pointer to class
instances just in order to field RTTI. That, of course, is where you
would put this information.

C++ is not type safe for pointers in any case, and defining this
otherwise would mean adding a virtual function table pointer for each
structure, which would make the language useless for any application
that needed to share data with other languages, or with hardware.

There seems to be no way round putting the dispatch table pointer
inside the structure because C++ is haunted by C's simplistic ideas
about arrays.


Post a followup to this message

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