C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The string returned by typeid(X).name()

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
thiago.adams@gmail.com
Guest





PostPosted: Wed Aug 03, 2005 3:28 pm    Post subject: The string returned by typeid(X).name() Reply with quote



Hello,
The string returned by typeid(X).name() must be equal for any compiler?
If I use this string for class serialization in text mode I can use the
serialization code in another compiler?
thanks


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

Back to top
Matti Rintala
Guest





PostPosted: Wed Aug 03, 2005 6:32 pm    Post subject: Re: The string returned by typeid(X).name() Reply with quote



[email]thiago.adams (AT) gmail (DOT) com[/email] wrote:
Quote:
The string returned by typeid(X).name() must be equal for any compiler?

There are no special requirements whatsoever for the string returned by
name(). The standard says:

18.5.1 (7):
"const char* name() const;

Returns: an implementation-defined NTBS.

Notes: The message may be a null-terminated multibyte string (17.3.2.1.3.2),
suitable for conversion and display as a wstring (21.2, 22.2.1.5)."

It also says:

18.5.1 (1):
"The names, encoding rule, and collating sequence for types are all
unspecified and may differ between programs."

So you really cannot rely on the string remaining the same even when using
the same compiler.

--
------------- Matti Rintala ------------ [email]matti.rintala (AT) tut (DOT) fi[/email] ------------
Painting is the art of inclusion. Photography is an art of exclusion.

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


Back to top
tony_in_da_uk@yahoo.co.uk
Guest





PostPosted: Wed Aug 03, 2005 6:33 pm    Post subject: Re: The string returned by typeid(X).name() Reply with quote



No - it can and does differ between compilers. Cheers, Tony


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

Back to top
Victor Bazarov
Guest





PostPosted: Wed Aug 03, 2005 6:34 pm    Post subject: Re: The string returned by typeid(X).name() Reply with quote

[email]thiago.adams (AT) gmail (DOT) com[/email] wrote:
Quote:
The string returned by typeid(X).name() must be equal for any compiler?

Nope.

Quote:
If I use this string for class serialization in text mode I can use the
serialization code in another compiler?

Nope. Not even with a different version of the same compiler.

There is no requirement in the Standard as to what that string should look
like or whether it should look meaningful at all.

V

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


Back to top
Gianluca Silvestri
Guest





PostPosted: Wed Aug 03, 2005 6:34 pm    Post subject: Re: The string returned by typeid(X).name() Reply with quote


<thiago.adams (AT) gmail (DOT) com> ha scritto nel messaggio
news:1123079214.990201.190290 (AT) o13g2000cwo (DOT) googlegroups.com...
Quote:
Hello,
The string returned by typeid(X).name() must be equal for any compiler?
If I use this string for class serialization in text mode I can use the
serialization code in another compiler?
thanks

No the string returned by type_info::name is implementation defined


---
Gianluca Silvestri


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


Back to top
Tom Widmer
Guest





PostPosted: Wed Aug 03, 2005 6:40 pm    Post subject: Re: The string returned by typeid(X).name() Reply with quote


[email]thiago.adams (AT) gmail (DOT) com[/email] wrote:
Quote:
Hello,
The string returned by typeid(X).name() must be equal for any compiler?
If I use this string for class serialization in text mode I can use the
serialization code in another compiler?

No, the string is implementation defined. The usual way around this is
to define some kind of ID for each polymorphic type you want to
serialize. See the boost serialization library (at www.boost.org) for
an example.

Tom


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


Back to top
richard@ex-parrot.com
Guest





PostPosted: Wed Aug 03, 2005 6:41 pm    Post subject: Re: The string returned by typeid(X).name() Reply with quote


[email]thiago.adams (AT) gmail (DOT) com[/email] wrote:
Quote:
Hello,
The string returned by typeid(X).name() must be equal for any compiler?

No, and it typically is not. It needn't even be equal between
recompilations using the same compiler. (This sometimes happens in
practice for types in anonymous namespaces.)

Quote:
If I use this string for class serialization in text mode I can use the
serialization code in another compiler?

Definitely not.

--
Richard Smith


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


Back to top
thiago.adams@gmail.com
Guest





PostPosted: Thu Aug 04, 2005 10:33 am    Post subject: Re: The string returned by typeid(X).name() Reply with quote

Thank's for all,

I think that is interesting make a table for result of typedid().name()
for diferent classes in diferent compilers. Mybe a function that
normalize the names is usefull.

I already see the boost serialization library, is very interesting.


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

Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Fri Aug 05, 2005 3:05 pm    Post subject: Re: The string returned by typeid(X).name() Reply with quote

[email]thiago.adams (AT) gmail (DOT) com[/email] wrote:

Quote:
I think that is interesting make a table for result of
typedid().name() for diferent classes in diferent compilers.

There was a proposal to standardize the naming. It was voted
down, I think because some compilers had implemented something
else, and didn't want to change.

Quote:
Mybe a function that normalize the names is usefull.

Note that the current standard doesn't even require the names to
be unique within a single compiler. An implementation which
always returned "" would be fully conforming. In fact, I would
not be surprised if some compilers didn't occasionally use the
same name for two different classes. (Sun CC does, for
example.)

--
James Kanze GABI Software
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


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


Back to top
jeff.koftinoff@gmail.com
Guest





PostPosted: Mon Aug 08, 2005 7:52 am    Post subject: Re: The string returned by typeid(X).name() Reply with quote

[email]kanze (AT) gabi-soft (DOT) fr[/email] wrote:
Quote:

snip

Note that the current standard doesn't even require the names to
be unique within a single compiler. An implementation which
always returned "" would be fully conforming. In fact, I would
not be surprised if some compilers didn't occasionally use the
same name for two different classes. (Sun CC does, for
example.)


What is the use of having a feature defined in the standard that is
fundamentally useless? Or is there some use that I can't think of that
is both standard-conforming and useful?

--
jeff koftinoff <jeff.koftinoff (AT) gmail (DOT) com>
www.jdkoftinoff.com


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


Back to top
msalters
Guest





PostPosted: Tue Aug 09, 2005 1:46 pm    Post subject: Re: The string returned by typeid(X).name() Reply with quote


[email]jeff.koftinoff (AT) gmail (DOT) com[/email] schreef:

Quote:
kanze (AT) gabi-soft (DOT) fr wrote:

Note that the current standard doesn't even require the names to
be unique within a single compiler. An implementation which
always returned "" would be fully conforming. In fact, I would
not be surprised if some compilers didn't occasionally use the
same name for two different classes. (Sun CC does, for
example.)


What is the use of having a feature defined in the standard that is
fundamentally useless? Or is there some use that I can't think of that
is both standard-conforming and useful?

Debugging, of course. Now, typeid(X).name may be somewhat less useful,
but consider typeid(*pX).name .

BTW, the standard in no way guarantees usefulness. It's legal to
throw std::bad_alloc from every new expression. Does that make
new useless?

HTH,
Michiel Salters


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


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.