I thought I did: the former can only be performed at run-time, hence
"Run Time Type Information", because no compiler can even _in principle_
predict the dynamic type of *p in the general case. The latter, compatibility
between throw statements and catch statements, can in principle be computed
at compile time as a huge matrix. The huge matrix is not very practical so
various optimizations are used, including RTTI, but that does not make
RTTI _required_; it's just one option among many.
But again: if you assume global program analysis, dynamic_cast may also
rely on a compatibility matrix between the locations were object instances
are created, and the calls to dynamic_cast. A huge matrix which may also
be 'optimized' in various ways.
The mechanism is still the same: some source type needs to be checked
for compatibility with some destination type, and a pointer offset has
to be applied.
The only difference I see is that, for dynamic_cast, the object's type
is typically stored with the object (e.g. in the vtbl). For EH, the
thrown type needs to be stored somewhere so that it can be matched
during stack-unwinding (to be accessible to catch()-handling code).
Or reciprocally, try-catch() blocks that are on the call stack need
to somehow be identified at run-time -- as you can't always know at
compile time where a throwing function has been called from.
No. Dynamically linked libraries are not part of C++. In a C++
implementation that supports dynamically linked libraries the most
natural way would be to use some form of RTTI, but I fail to see
any proof that RTTI is required in this case (with some more constraints
imposed, e.g. current linker technology, such a proof may be possible).
The reality of C/C++ today is separate compilation and limited
support for whole program optimization. But I agree that the standard
says very little about separate compilation.
Maybe in the informative annex about C compatibility (C1.6/2):
"When comparing types in different compilation units, C++ relies on
name equivalence when C relies on structural equivalence."
....
Do you have any references for that rumour?
I have no concrete information about what these 'reservations' were.
But I remember reading about the common underlying mechanism in
several instances.
What a quick google search brings:
Bruce Eckel's Thinking in C++, 2nd ed., Volume 2, Revision 2:
About RTTI:
"When exception handling was added to C++, it required the exact type
information about objects. It became an easy next step to build access
to that information into the language."
http://nicolas.blancpain.free.fr/Documents/Cpp/onlinev2/Chapter08.html
Some random web doc:
"Why might RTTI be useful?
Input of objects (what kind is it?), OODBs, debugging
Despite Stroustrup's reservations, RTTI adopted by
ANSI/ISO committee (Borland 4.0)
Why is RTTI already implied by exception handling?
catch needs to discriminate types"
http://www.eecs.lehigh.edu/~glennb/oose/13exRTTI.doc
NB: BS actually proposed RTTI in the form of dynamic_cast:
"BS: Yes, I was the one who invented the dynamic_cast syntax to
parallel the syntax for explicitly qualified template function calls.
Together with Dmitry Lenkov from HP, I was the proposer of the
runtime type identification (RTTI) mechanisms.
RTTI is easily overused. However, ...."
http://www.research.att.com/~bs/omo_interview.html
Nothing that authoritative indeed. I don't have BS's D&E
or his other books here to look for a quote.
Maybe some committee member could help here...
Kind regards,
Ivan