typeinfo comparison - 'is' or '=='?

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Sun May 7 11:39:45 PDT 2006


Anders F Björklund wrote:
> Gregor Richards wrote:
> 
>> I've ran into an issue with typeinfo objects.  It seems that for any 
>> type, there should be a static object containing the type info, and 
>> furthermore there should only be one in the output program.  My 
>> reasoning behind this is that several .d files in phobos/ use 'is' to 
>> compare typeinfo's, which implies to me that the 'typeid' operator 
>> will return a reference to a statically declared type (since otherwise 
>> it could return a different value and you'd get false negatives)
> 
> This is a problem for GDC too, when running on old compilers (GCC 3.3) 
> that doesn't support once-only linkage and therefore duplicates objects.
> 
> http://www.digitalmars.com/d/archives/D/gnu/1594.html
> 
>> So my question is: Am I wrong, or is the code in phobos/std/boxer.d 
>> and phobos/std/stream.d wrong?
> 
> Well, not "wrong" - it is just not portable ? But changing it from 'is'
> over to use '==' instead would make it work in more places than it does.
> 
> So I think that Phobos should be changed.
> 
> --anders

Whoa there, I just realized: This is a global language issue, it is not 
just a matter of Phobos. It has to be defined globally (by the language 
itself) what is the correct way to compare two types.
I mean, what if in a D program one uses == / is with a TypeInfo? 
Wouldn't GDC support == ?

-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list