This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: typeid().name syntax


<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/



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]