This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: typeid().name syntax
- To: comp-std-c++ at moderators dot isc dot org
- Subject: Re: typeid().name syntax
- From: ncm at nospam dot cantrip dot org (Nathan Myers)
- Date: 5 Nov 1998 10:15:54 -0800
- Newsgroups: comp.std.c++,comp.lang.c++.moderated
- Organization: http://www.cantrip.org/
- References: <36373B0D.93BE21C2@friko6.onet.pl> <363C768B.4FB4B5A3@acm.org> <slrn6uodi9.ohq.sbnaran@localhost.localdomain> <71q4cp$bdm$1@nnrp1.dejanews.com>
<AllanW@my-dejanews.com> wrote:
>I compiled this code on [...]
> #include <iostream>
> class C { int x; };
> int main() {
> std::cout << typeid(::C).name() << std::endl;
> class C { float x; };
> std::cout << typeid(C).name() << std::endl;
> { class C { char *x; };
> std::cout << typeid(C).name() << std::endl; }
> }
>The result was:
> class C
> class C
> class C
>Would someone please confirm that this is NOT what was
>supposed to happen?
It is *precisely* what is supposed to happen, on your compiler.
Here is all the standard says:
const char* name() const;
Returns: an implementation-defined NTBS.
An implementation is allowed to define name() to return the
empty string for all types.
If you don't like how your implementer defined it, your
only recourses are to (1) persuade them to define it more
to your liking, or (2) switch to a compiler you like better.
Perhaps the nicest definition would be one that lets you hook
in your own "remangler" (or one of theirs) at link-time. I
suspect it will be a while before any implementer does that,
but any could add it any time.
--
Nathan Myers
ncm@nospam.cantrip.org http://www.cantrip.org/