Consider following example:
#include <iostream>
#include <typeinfo>
int main()
{
int a=9;
std::cout << typeid(a).name() << '\n';
}
Output on g++ 4.8.1 : i
Output on MSVS 2010: int
Why output is compiler depedent? What is the reason behind this? Why it is left as implementation defined? Why not same output on all compilers? Does C++ standard says it explicitly?
Because compilers represent types differently and don't use the same internals.
The G++ string is the mangled type name, returning that (rather than demangling it) is less work and more efficient. Requiring compilers to demangle those strings would add more work. The standard leaves it up to implementors to decide if they want to do that.
If the standard dictated it then it would also have to specify all sorts of things, like whether to say signed long
or just long
and how to represent complex template instantiations that depend on other types and constants. The benefits of standardising those strings would be very small, but a large amount of work.