Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

activate RTTI in c++

Tags:

c++

hp-ux

rtti

acc

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.

like image 330
Vijay Avatar asked Apr 14 '10 05:04

Vijay


People also ask

How do I enable RTTI in C++?

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.

What is FNO RTTI?

-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.

Why do we need RTTI?

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.

What is RTTI C++?

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.


2 Answers

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

UPDATE

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.

like image 62
vladr Avatar answered Sep 28 '22 22:09

vladr


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 
like image 21
Eddy Pronk Avatar answered Sep 28 '22 23:09

Eddy Pronk