Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Exceptions don't need RTTI and have only runtime cost when thrown.


Exceptions actually can need RTTI, though not necessarily all of the RTTI that things like <typeinfo> provide. For some details, see the -fno-rtti flag for GCC, for which the documentation says[1]:

Disable generation of information about every class with virtual functions for use by the C++ runtime type identification features (`dynamic_cast' and `typeid'). [...] Note that exception handling uses the same information, but it will generate it as needed.

[1]: https://gcc.gnu.org/onlinedocs/gcc-4.6.1/gcc/C_002b_002b-Dia...


That is a compiler specific implementation, the ANSI C++ standard doesn't require it.


That's great and all but when every modern compiler does implement it that way it's not something you can ignore.

Show me a compiler that's used in production which handles multi-inheritance exceptions without allocating extra data and I'll be happy to eat my words :).


Sadly I cannot pay for all commercial compilers out of my own pocket. :)


The ANSI C++ standard requires exceptions in the first place. The moment we start talking about disabling them, we're not talking about standard C++ anymore.


Which is why people cannot just state "In C++ the thing X happens" without regarding what the standard says, instead of what the installed compiler does.

Language != Implementation.

If the language would be "In GCC the thing X happens when ...", then ok.


For all practical purposes, the most popular implementations are the language. You can only ignore that in an academic context.


Popular where? Not everyone uses GCC.


> Exceptions don't need RTTI and have only runtime cost when thrown.

No, they add extra control flow edges, which inhibit optimizations, affecting runtime performance. This is a lot of the reason why unwinding is optional in Rust.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: