Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When can compiling c++ without RTTI cause problems?

Tags:

c++

gcc

rtti

I'm using gcc's -fno-rtti flag to compile my C++ without runtime type information.

Assuming I'm not using dynamic_cast<> or typeid(), is there anything that could lead me to later problems?

like image 551
McPherrinM Avatar asked Dec 20 '10 03:12

McPherrinM


People also ask

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.

What is Frtti?

Enables support for run-time type information (RTTI).

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.

How do I enable RTTI in C++?

RTTI will be enabled or disabled when compiling your program via compiler options - it's not something enabled or disabled in the Unix environment globally. The easiest way to see if it's enabled by default for your compiler is to just try compiling some code using RTTI.


2 Answers

Since your question is specific to GCC you should consult carefully the documentation for the version you are using. The documentation for GCC 4.5.2 says the following. Which from my reading would indicate that if you avoid dynamic_cast and typeid, you should be ok. That said, I have no personal experience with -fno-rtti. Perhaps you might like to elaborate on why you are using -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. Note that exception handling uses the same information, but it will generate it as needed. The dynamic_cast operator can still be used for casts that do not require runtime type information, i.e. casts to void * or to unambiguous base classes.

There is discussion about the relationship between virtual functions and RTTI available at No RTTI but still virtual methods. The short version is that virtual functions should be fine without RTTI.

like image 193
Bowie Owens Avatar answered Oct 08 '22 04:10

Bowie Owens


We have used gcc without rtti for 5 years with no specific problems (not using dynamic_cast or typeid)

like image 29
Steve Avatar answered Oct 08 '22 06:10

Steve