1

I vaguely remember i've heard someone saying, that the run-time type identification might not work in some special cases. Therefore i would like to ask: Does C++ RTTI work always on all platforms with default settings, or is there a case where it might not be implemented or where you need to explicitely enable it by an command line argument?

Youda008
  • 1,788
  • 1
  • 17
  • 35

2 Answers2

2

No, not always.

For example, it's off by default in Android, though there you can simply enable it.

Such C++ implementations are technically non-compliant whilst RTTI or exceptions are disabled.

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
1

Especially for small embedded system RTTI is not available. Another example is 8 bit AVR target.

The reason is quite simple: RTTI needs more memory for the information itself. So for small embedded systems it is typically off by default or it is simply not implemented for the target like with avr-gcc.

Normally in c++ it is guaranteed that you pay not for things you do not use. But RTTI is one example where you need more memory also if you don't use it until you switch it off for your modules which do not need RTTI.

Klaus
  • 24,205
  • 7
  • 58
  • 113
  • and what about exceptions? it is the same? – Youda008 Jun 07 '15 at 14:06
  • @Youda008: It is not exact the same. Some compilers can generate on some targets code also with exception handling without a general overhead. But yes, exception handling generate a overall overhead on some environments. – Klaus Jun 08 '15 at 10:43