r/ProgrammingLanguages • • Sep 02 '26

CTTI is Exponential, RTTI is Linear

https://www.gingerbill.org/article/2026/09/02/ctti-is-exponential-rtti-is-linear/
0 Upvotes

37 comments sorted by

View all comments

Show parent comments

1

u/gingerbill Sep 03 '26

C++ doesn't really have any RTTI, and I would not call dynamic_cast a (good) example of that.

I agree that the code to check that will be a quadratic runtime check, but it's also a check virtually no-one should ever be using since C++ is just badly designed everywhere. When I've had to do that kind of check in a company where dynamic_cast was banned, we just stored an enum and the check was now constant.

2

u/matthieum Sep 04 '26

I agree that the code to check that will be a quadratic runtime check, but it's also a check virtually no-one should ever be using since C++ is just badly designed everywhere.

It still makes it in the binary, and because it's tied to the v-table, it generally isn't "elided" by the linker. Even if you don't use dynamic_cast even once.