Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is type_info::name() unspecified?

Tags:

c++

typeinfo

I'm fully aware that the return value of std::type_info::name() is implementation-defined.

From the C++ standard (ISO/IEC 14882:2003 §18.5.1.7):

Returns: an implementation-defined NTBS.

My question is: why? Wouldn't this member function be much more useful if the standard dictated what the return value should be?

like image 407
mtvec Avatar asked Aug 25 '10 08:08

mtvec


2 Answers

Basically, if an implementation decides that they can't or doesn't want to support RTTI, they can just return "";. If the standard forced it to return something, they'd possibly kill any ability to have a compliant compiler for an environment where the resources for RTTI don't exist or want to be disabled (a microchip, for example.)

And let's not forget we don't want to force an ABI/name-mangling scheme on any compilers.

This follows the C++ philosophy "You don't pay for things you don't need."

like image 56
GManNickG Avatar answered Oct 08 '22 06:10

GManNickG


Where we're talking about vendors returning different strings, I think it's just a "we do it this way, you change" "no, we do it this way, YOU change" thing between the compiler vendors. Even the Standards committee doesn't want to annoy the compiler teams, and creating some neutral, new standard that isn't employed by any vendor tends to mean finding something that's nonsensical anyway.

Why aren't they all the obvious namespaces::class::functions etc. already? Some current implementations may have historically found it convenient to have it match the linker-required mangled names, been paranoid (or had paranoid clients) re memory usage etc..

like image 2
Tony Delroy Avatar answered Oct 08 '22 05:10

Tony Delroy