1

In my C++ application, I use RTTI for dynamic_cast and such. Looking through the compiled binary, I notice that quite a bit of data is generated to store type names for typeinfo structs. Since I don't use type names at all, is there are a way to disable this part of RTTI while still allowing dynamic_cast to work?

EDIT

I am using GCC (G++) for ARM

arm-none-eabi-g++.exe (GNU Tools for STM32 10.3-2021.10.20211105-1100) 10.3.1 20210824 (release)

Patrick Wright
  • 1,401
  • 7
  • 13
  • 1
    [signs point to maybe](https://stackoverflow.com/questions/7687041/dynamic-cast-with-rtti-disabled) – NathanOliver May 27 '22 at 20:06
  • When you say "compiled binary", do you mean your final target executable? – Eljay May 27 '22 at 20:12
  • 1
    Which compiler? This would not be something standardized. – user17732522 May 27 '22 at 20:47
  • `type_info` is for classes, not objects. You will not get names in each object. So it will not lead to efficiency issue since the string is store once for each class. – yao99 May 27 '22 at 23:33
  • Related: https://stackoverflow.com/q/11403136 – Artyer May 28 '22 at 06:07
  • Most RTTI implementations I've seen are heavily dependent on string comparisons for dynamic cast. If you're just doing single inheritance, or possibly even some limited multiple inheritance you can implement your own casting with `static_cast` as long as you can validate the type, but if you're using virtual inheritance then you really do need the RTTI and `dynamic_cast`. – vandench May 31 '22 at 14:03

0 Answers0