Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Decode output from typeid().name()

313 views
Skip to first unread message

C.W.Holeman II

unread,
Feb 16, 2009, 6:27:02 PM2/16/09
to
Is there a reference that decodes the output from typeid().name()?

----- x.cxx ------
#include <iostream>
#include <typeinfo>
class X {
public:
template<typename T> X& operator<<(T const& a_v){
std::cout << typeid(T).name() << std::endl;
}
};
int main(){
X x;
x << "Hello, world!";
x << 1;
x << -1.234;
x << x;
}
-------------------

---- output -----
A14_c
i
d
1X
------------------

--
C.W.Holeman II cwh...@Julian5Locals.com-5s http://JulianLocals.com/cwhii
To only a fraction of the human race does God give the privilege of
earning one's bread doing what one would have gladly pursued free, for
passion. I am very thankful. The Mythical Man-Month Epilogue/F.P.Brooks

Pedro Lamarão

unread,
Feb 17, 2009, 8:19:21 AM2/17/09
to
On 16 fev, 20:27, "C.W.Holeman II" <cwhii_google_s...@yahoo.com>
wrote:

> Is there a reference that decodes the output from typeid().name()?

The C++ Standard does not specify the value of that expression.
It could very well be the null string in a conforming specification.

--
P.

C.W.Holeman II

unread,
Feb 17, 2009, 10:13:06 AM2/17/09
to

Which is the reason I posted to gnu.g++.help not c++.

Pedro Lamarão

unread,
Feb 18, 2009, 3:05:38 PM2/18/09
to
On 17 fev, 12:13, "C.W.Holeman II" <cwhii_google_s...@yahoo.com>
wrote:

> Pedro Lamarão wrote:
> > On 16 fev, 20:27, "C.W.Holeman II" <cwhii_google_s...@yahoo.com>
> > wrote:
>
> >> Is there a reference that decodes the output from typeid().name()?
>
> > The C++ Standard does not specify the value of that expression.
> > It could very well be the null string in a conforming specification.
>
> Which is the reason I posted to gnu.g++.help not c++.

Good point.

GCC implements the Itanium C++ ABI, specified here:

http://www.codesourcery.com/public/cxx-abi/abi.html

You will see that, contrary to my expectation, this specification does
in fact guarantee some form to that expression.
Search for the demangler API.

--
P.

C.W.Holeman II

unread,
Feb 19, 2009, 1:15:28 AM2/19/09
to

Thanks.

#include <iostream>
#include <typeinfo>
#include <cxxabi.h>
class X {
public:
template<typename T> void operator[](T const&){
size_t len;
int s;
char* p=abi::__cxa_demangle(typeid(T).name(), 0, &len, &s);
std::cout << typeid(T).name() << ": " << p << std::endl;


}
};
int main(){
X x;
x["Hello, world!"];
x[1];
x[-1.234];

x[x];

0 new messages