[GiNaC-list] Problem using a user-defined class on Mac OS X.

David Fang fang at csl.cornell.edu
Thu Apr 5 21:38:33 CEST 2007


> > That's a different story. What we have is _equivalent_ explicit
> > specialization, like
> >
> > template<typename T> class bar {
> > 	static void* data;
> > };
> >
> > template<typename T> bar<T>::data = 0;
> >
> > struct baz { };
> >
> > // in a different translation unit:
> >
> > template<> bar<baz>::data = 0;
> >
> > So there should be no any difference. But... Apparently compiler generates
> > different code:
>
> The difference is that the former definition is a template, and thus
> symbols created by its instantiations are given weak-extern linkage, i.e.

I should qualify that as *implicit* instantiations.  Explicit
instantiations might be non-weak, IIRC -- explicit and redundant
instantiations will resut in 'multiply-defined' link diagnostics.

> there may be multiple instantiations in different translation units, the
> linker will just pick any one for reference resolution purposes.  The
> latter (full specialization) is no longer a template and given
> non-weak-external linkage.  (Enforcing the ODR is one way to avoid this
> problem.)  Hence, you see different linkage classifications shown by nm.
> Someone correct me if I'm wrong.

Fang


David Fang
Computer Systems Laboratory
Electrical & Computer Engineering
Cornell University
http://www.csl.cornell.edu/~fang/
	-- (2400 baud? Netscape 3.0?? lynx??? No problem!)



More information about the GiNaC-list mailing list