When can compiling c++ without RTTI cause problems?

主宰稳场 提交于 2019-12-03 04:04:58

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/4486609/when-can-compiling-c-without-rtti-cause-problems

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!