From: german diago on
Demangling in c++ is compiler-dependant. Why isn't there any proposal
for an API that demangles types (typeid) to its real c++ name. I mean
if you have mylib::mytype and you use typeid(mylib::mytype).name() you
get a name which depends on the compiler. It would be nice to be able
to do something like std::demangle(typeid(mylib::mytype)) because this
way you can do many things portable. Like for example (which is my use
case):


class Signal {
private:
std::string name_;
public:
Signal(const std::string & signame)
{
name_ = std::demangle(typeid(Signal)) + "::" + name;
}
};

This would allow introspection of signals in my code in a portable way.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Neal E. Coombes on
On Apr 8, 2:25 pm, german diago <germandi...(a)gmail.com> wrote:
> Demangling in c++ is compiler-dependant. Why isn't there any proposal
> for an API that demangles types (typeid) to its real c++ name. I mean
> if you have mylib::mytype and you use typeid(mylib::mytype).name() you
> get a name which depends on the compiler. It would be nice to be able
> to do something like std::demangle(typeid(mylib::mytype)) because this
> way you can do many things portable. Like for example (which is my use
> case):
>
> class Signal {
> private:
> std::string name_;
> public:
> Signal(const std::string & signame)
> {
> name_ = std::demangle(typeid(Signal)) + "::" + name;
> }
>
> };
>
> This would allow introspection of signals in my code in a portable way.

I've begun an attempt at something similar:

http://toast.sourceforge.net/classtoast_1_1type__info.html

I've only unified the type info between g++ and Sun CC so far (since
that's what we use), but I'd be thrilled to add another compilers type
info!

Neal

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: marlow.andrew on
On 8 Apr, 20:25, german diago <germandi...(a)gmail.com> wrote:
> Demangling in c++ is compiler-dependant. Why isn't there any proposal
> for an API that demangles types (typeid) to its real c++ name.

If only the ABI could be stdardized you would not need an API. Anyone
could write a portable routine to do it. But I do not think the ABI
will ever be stdized. Stroustrup does not want the stdization
committee to look at such stdization. I know, I asked him. His
response was it was an issue for compiler implementers to sort out.
The trouble is, compiler implementers have enough trouble stdizing the
ABI between versions of their own compiler, let alone having a std for
all compilers. So I think they will never sort it out. Or if they do
it will be so many years down the line it won't matter. It certainly
won't be in time for you.

I think you are going to have no choice but to reverse-engineer it for
each platform/compiler that you want to support.

Regards,

Andrew Marlow

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Mathias Gaunard on
On Apr 10, 11:21 pm, marlow.and...(a)googlemail.com wrote:

> If only the ABI could be stdardized you would not need an API. Anyone
> could write a portable routine to do it. But I do not think the ABI
> will ever be stdized.

There is an industry standard for the C++ ABI. It's the Itanium C++
ABI.
I think all compilers but windows ones follow it.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: marlow.andrew on
On 11 Apr, 05:43, Mathias Gaunard <loufo...(a)gmail.com> wrote:
> On Apr 10, 11:21 pm, marlow.and...(a)googlemail.com wrote:
>
> > If only the ABI could be stdardized you would not need an API. Anyone
> > could write a portable routine to do it. But I do not think the ABI
> > will ever be stdized.
>
> There is an industry standard for the C++ ABI. It's the Itanium C++
> ABI.
> I think all compilers but windows ones follow it.

I thought that the itanium std was processor-specific but after a bit
of googling
it looks like it has emerged as a de facto std. But this is quite
recent.
For example, GCC only supports the itanium ABI as of version 4.x.y.
This is fine for use by enthusiasts but I don't think it is of much
help
in a commercial env where typically much older versions of GCC are in
use.
Also I strongly suspect that many commercial compilers commonly in use
do not support it. I am thinking of Sparcworks, Forte and Visual
Studio 8,
which are the common compilers used on solaris. And of course if the
Microsoft compilers ignore it (suprise, suprise) then even if everyone
else
did support it there would still be an incompatibility between Unix
and Windoze,
so the OP would still have to write typeid demangling code with ifdefs
that
distiniguish between these platforms.

-Andrew Marlow

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]