Can anybody tell me how to activate RTTI in c++ when working on unix. I heard that it can be disabled and enabled. on my unix environment,how could i check whether RTTI is enabled or disabled?
I am using the aCC
compiler on HPUX.
In g++ you can test the __GXX_RTTI macro to see if RTTI is on in your code. As others have pointed out -no-rtti turns of RTTI in g++. I would bet both these things work in clang as well. In newer C++ we will have access to feature testing macros __cpp_rtti and many others that will make tese things easier.
-fno-rtti. Disable generation of information about every class with virtual functions for use by the C++ runtime type identification features (` dynamic_cast ' and ` typeid '). If you don't use those parts of the language, you can save some space by using this flag.
RTTI, Run-Time Type Information, introduces a [mild] form of reflection for C++. It allows to know for example the type of a super class, hence allowing to handle an heterogeneous collection of objects which are all derived from the same base type. in ways that are specific to the individual super-classes.
Run-time type information (RTTI) is a mechanism that allows the type of an object to be determined during program execution. RTTI was added to the C++ language because many vendors of class libraries were implementing this functionality themselves.
Are you using g++
or some other compiler?
In g++
RTTI is enabled by default IIRC, and you can disable it with -fno-rtti
. To test whether it is active or not use dynamic_cast
or typeid
I believe that HPUX's aCC
/aC++
also has RTTI on by default, and I am unaware of a way to disable it. Check your man
pages.
gcc has it on by default. Check if typeid(foo).name() gives you something useful.
#include <iostream> #include <typeinfo> int main() { std::cout << typeid(int).name() << std::endl; return 0; }
Without RTTI you get something like:
foo.cpp:6: error: cannot use typeid with -fno-rtti
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With