问题
I remember coding on platforms that had both RTTI and exceptions disabled, and on others that had them both enabled. However, I cannot remember coding on a platform that would enable one and disable the other one.
Is there any kind of dependency between the two concepts? Said differently, do exceptions need RTTI to function? Or the contrary?
回答1:
No, Exceptions do not need RTTI functionality neither vice versa both are separate features.
Some of the implementations might allow you to disable exceptions(-fnoexceptions in gcc) but I don't know of any implementation which needs RTTI for exceptions or vice versa.
回答2:
They are not dependent on each other but they are both heavy features so if there is a platform that has bad performance they will probably both be cut together.
回答3:
I was just reading this C++ proposal "Zero-overhead deterministic exceptions: Throwing values" (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r0.pdf?), in which I read:
"C++ allows there to be multiple active exception objects of arbitrary types, which must have unique addresses and cannot be folded; and it requires using RTTI to match handlers at run time, which has statically unpredictable cost on all major implementations and can depend on what else is linked into the whole program."
and elsewhere it is stated that:
"4) Today’s dynamic exceptions require using some form of RTTI to match handlers."
Thus, it appears there is a relation between exceptions and RTTI
来源:https://stackoverflow.com/questions/10320072/is-there-a-relation-between-rtti-and-exceptions