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

Sean Kelly sean at f4.ca
Sun May 7 12:00:11 PDT 2006


Gregor Richards wrote:
> Partially to learn the DMD frontend and partially because it's cool and 
> useful, I've been writing a D compiler targetting C ( 
> http://www.dsource.org/projects/tdc/ )
> 
> 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.

That's right.

> 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)
> 
> Unfortunately, this poses a bit of a problem when using .c as the 
> output.  Anything I try to declare statically would end up declared into 
> every .o file.  That's a (slightly) solvable problem with some linkers, 
> but probably unsolvable with .so-linkage or .dll-linkage, unless I'm 
> misunderstanding the situation.

Why not create a source file with all the declarations and a header 
file, included by everything, that has an "extern" declaration for each one?


Sean



More information about the Digitalmars-d mailing list