Article View: comp.std.c++
Article #2983RTTI implementation...
From: J. Greenblatt
Date: Fri, 05 Jan 1996 19:32
Date: Fri, 05 Jan 1996 19:32
60 lines
2816 bytes
2816 bytes
I have been discussing RTTI with a person at work and have a
suggestion I would like to share.
Problem:
It seems that RTTI requires a compile time flag to be activated. When
activated the code seems to bloat whether you actualy use the feature in the
specific peice of code or not. From what I have learned this overhead is due
to extra work done when the object is constructed (A pointer to this with a
string representation of the class is added to a table). This overhead does
not make RTTI a good addition to C++ but more of a optional addition to those
who want it (this is how it is implemented now). Also are the addition of key
words which is not a biggy in this case given the key word names.
Proposed solution:
Allow RTTI to be implemented on the whole system as it is now and keep
it as a option. In addition allow RTTI to be turned on on a class by class
basis. On a class by class basis RTTI would be enabled if a base of the
current class is declared with the RTTI keyword. The extra RTTI keywords
(dynamic_cast, static_cast, etc...) are only defined for classes declared
as RTTI classes. The RTTI overhead is now only felt when accessing objects
of RTTI classes.
Example:
// This is a non RTTI enabled class, no RTTI overhead, no RTTI keywords
class foo
{
int i;
};
// This is a RTTI class with the RTTI overhead, RTTI keywords enabled.
RTTI class bar
{
int i;
};
// This is also a RTTI class by inheritence
class baz: public bar
{
int k;
};
Conclusion:
I may have not considered all the issues here but I think the RTTI
keyword would be a good way of using RTTI without being hit with the extra
overhead when not needed. If the RTTI compiler option is used, all classes
are RTTI classes whether RTTI is specified or not. Some vendors may want
to experiment with it or add this capability as an extension to their
compilers. If the RTTI keyword is used as an "extension", you could #define
RTTI to be nothing on compilers that do not support it and turn the RTTI
compiler flag making all classes RTTI, this will allow your code to be
portable accross compilers that do not support the conditional RTTI keyword.
A lot of what I seen of RTTI is based on MicroSlof so other
implementations or RTTI may or may not have the problems I described in
the problem section.
JonG.
Technical Details
Message-ID:
<4ciauq$2e1@trojan.neta.com>Path:
arc1-ca.pugleaf.net!chronicle.mti.sgi.com!newsShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!news From: jonnyg@trojan.neta.com (J. Greenblatt) Newsgroups: comp.std.c++ Subject: RTTI implementation... Date: 05 Jan 1996 19:32:45 GMT Organization: Internet Access, Chandler AZ. Approved: austern@mti.sgi.com Message-ID: <4ciauq$2e1@trojan.neta.com> Reply-To: jgreen@amex-trs.com NNTP-Posting-Host: isolde.mti.sgi.com Summary: Make RTTI conditional by class. Keywords: RTTI