Re: why are foos like vector<T>::size no duplicate symbols for linker?
ajk wrote:
On Fri, 27 Jun 2008 12:32:15 -0700 (PDT), vl106 <vl106@hotmail.com>
wrote:
- why does linker not complain about ctor being there 2-times?
- does linker "strip away" compiler generated template functions (if
necessary)?
- in MSVC map file: does "i" mean: internally created by compiler?
0002:00000990 ?f_a@@YAXXZ 00411990 f a.obj
0002:000009c0 ??0?$ARRAY@H@@QAE@H@Z 004119c0 f i a.obj
0002:00000a10 ?f_b@@YAXXZ 00411a10 f b.obj
for the same reason that
void f_a()
{
int a[3];
}
void f_b()
{
int a[5];
}
compile and link.
The arrays are not in the global namespace, they are locally declared
and alloacted on the stack in each function.
Actually, it's for a completely different reason.
You're correct that the two instances of a[] in the example above are not in
the same scope so they don't cause conflicts. In fact, the a's in the above
have no linkage at all - the names are invisible to the linker.
In the case of templates, it doesn't cause a linker error because C++
standard requires that it not cause a linker error. The mechanism by which
this is accomplished in VC++ is by using "named common blocks". These are
blocks that the linker automatically combines, overlaying all identical
definitions into a single region of memory in the linked image. This
mechanism is also used for functions that are declared as inline but are
actually implemented out of line by the compiler.
-cd