Topic: Enabling RTTI on a per-class basis
Author: stephen.clamage@sun.com (Steve Clamage)
Date: Wed, 25 Aug 2004 17:24:17 GMT Raw View
Laurie Cheers wrote:
> Is there any reason why RTTI can't be explicitly enabled for specific classes
> (and their children), even when the RTTI compiler flag isn't set?
>
> I'd like the ability to enable RTTI for the classes that need it, without
> incurring the extra space overhead for EVERY polymorphic object in existence.
As soon as you said "compiler flag" you moved outside the realm of the
C++ Standard.
The Standard says that RTTI is provided by the C++ implementation. A
compiler might choose to provide options to control RTTI, but to
conform to the Standard, RTTI must be enabled.
(OK, a compiler might do whole-program analysis to determine which
RTTI data was not needed, and remove unused data from the program.
Such an implementation would be standard-conforming under the "as-if
rule." No program with defined behavior could determine that some RTTI
data was missing.)
Your wish should be directed to your favorite compiler vendor.
---
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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: stefan_heinzmann@yahoo.com (Stefan Heinzmann)
Date: Thu, 26 Aug 2004 00:56:47 GMT Raw View
Laurie Cheers wrote:
> Is there any reason why RTTI can't be explicitly enabled for specific classes
> (and their children), even when the RTTI compiler flag isn't set?
>
> I'd like the ability to enable RTTI for the classes that need it, without
> incurring the extra space overhead for EVERY polymorphic object in existence.
The overhead is typically not per object, but per class, as RTTI only
adds entries to the vtable. The object itself does not grow due to RTTI,
as it already has a pointer to the vtable.
--
Cheers
Stefan
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: news@news.newshosting.com ("news")
Date: Thu, 26 Aug 2004 00:56:48 GMT Raw View
"Laurie Cheers" <laurie.cheers@btinternet.com> wrote in message news:c26006e0.0408240501.705465df@posting.google.com...
> Is there any reason why RTTI can't be explicitly enabled for specific classes
> (and their children), even when the RTTI compiler flag isn't set?
What makes you think that it needs to be. What good is a polymorphic
class that can't identify the type? dynamic_cast is pretty much parasitic
on the code that has to be there to handle virtual functions. The only thing
that takes the TINYEST amount of extra per-class overhead is support
for dynamic typeinfo.
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: laurie.cheers@btinternet.com (Laurie Cheers)
Date: Tue, 24 Aug 2004 23:47:45 GMT Raw View
Is there any reason why RTTI can't be explicitly enabled for specific classes
(and their children), even when the RTTI compiler flag isn't set?
I'd like the ability to enable RTTI for the classes that need it, without
incurring the extra space overhead for EVERY polymorphic object in existence.
For example, I would like to be able to write:
// a normal class with no RTTI space overhead
class A
{
};
// a child class with RTTI enabled, regardless of compiler flags
dynamic_cast class B: public A
{
};
// a child class which implicitly has RTTI enabled.
class C : public B
{
};
B* b = new C();
dynamic_cast<C>( b ); // perfectly normal dynamic_cast
A* a = new C();
dynamic_cast<B>( a ); // compiler error, A has no RTTI available
Does that seem reasonable?
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]