* Win32 issues with Templates and Libs *
Walter Bright
newshound at digitalmars.com
Tue Feb 20 10:46:39 PST 2007
Sean Kelly wrote:
> Let's back up for a second. First, in the situation Kris mentioned, how
> many instances of Test!(char) exist altogether?
One.
> I had expected there to
> be two: one in test.lib and one in tester.obj. But in this case I
> wouldn't expect the link error to occur, so perhaps you're saying that
> when the compiler sees "Test!(char) Global" in module test, it doesn't
> bother to create one in tester.obj?
That's right.
> Also, how do COMDATs differ from normal code blocks?
COMDATs are each placed in their own segment.
> ie. Why is the
> linker able to resolve normal symbols in libraries but not templates?
Because normal symbols cannot appear multiple times (if they did, you
get multiple definition errors at link time).
> Wouldn't the symbol name in both cases be enough to sort things out?
No.
> I guess this answers my question above: the compiler sees "Test!(char)
> Global" and doesn't bother to create another instance of the code. But
> surely being able to create a functional application is preferable in
> this case. Won't an optimizing linker throw out duplicates anyway?
The problem is not knowing which module to link in - after all, there
are (possibly) other global symbols in the module.
> Who
> cares if the object files are bloated, if that's the only workable
> option here?
You'll care <g> once templates get complex enough. It's been a big
problem with C++.
> Or perhaps this suggests the need for a D linker that
> builds a catalog of symbols inside libraries before linking instead of
> the behavior you describe above?
Building a linker or object file with non-standard semantics has its own
set of problems.
More information about the Digitalmars-d
mailing list