* Win32 issues with Templates and Libs *
Kristian Kilpi
kjkilpi at gmail.com
Tue Feb 20 12:58:09 PST 2007
On Tue, 20 Feb 2007 20:46:39 +0200, Walter Bright
<newshound at digitalmars.com> wrote:
> 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.
>
[snip]
For a person which doesn't know how linkers and object files work, this
seems to be an 'interesting' problem. <g>
I mean, there is an instance of Test!(char) in test.lib, but the linker
doesn't found it because there might be another instance in another object
file? And at the same time, the compiler tries to ensure that there will
be only one instance of Test!(char)...
What will be the number of instances of Test!(char) if test.d does not
contain 'Test!(char) Global;', and I have another module tester2.d,
similar to tester.d, which also uses the Test!(char) class? I except two,
one for tester.d and one for tester2.d. That is, at least, when the files
are compiled independently. And if the compiler would be smart enough to
create only one instance in that case, doesn't it mean the same linker
error will occur then too?
More information about the Digitalmars-d
mailing list