typeinfo comparison - 'is' or '=='?
Gregor Richards
Richards at codu.org
Sat May 6 19:32:26 PDT 2006
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. 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.
So my question is: Am I wrong, or is the code in phobos/std/boxer.d and
phobos/std/stream.d wrong?
- Gregor Richards
More information about the Digitalmars-d
mailing list