[GiNaC-list] Problem using a user-defined class on Mac OS X.
David Fang
fang at csl.cornell.edu
Thu Apr 5 21:29:22 CEST 2007
Hi again,
> > template <> void* foo<void*>::data = &something_else;
> >
> > which is similar to the original code in this thread. The instantiation
> > of foo<void*>::data can now be different-valued. (Is this analogous to
> > the GiNaC source or proposed patch in question?)
>
> 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.
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.
> // With explicit specialization
> $ nm -B -C build/ginac/ginac/.libs/libginac.so | grep -e '::first'
> 0032bc8c B GiNaC::class_info<GiNaC::print_context_options>::first
> 0032bc84 B GiNaC::class_info<GiNaC::registered_class_options>::first
>
> // _Without_ explicit specialization
> nm -B -C build/ginac/ginac/.libs/libginac.so | grep -e '::first'
> 002611d0 V GiNaC::class_info<GiNaC::print_context_options>::first
> 00261168 V GiNaC::class_info<GiNaC::registered_class_options>::first
>
> I need to re-read the standard to understand what's going on...
It is not fun reading material. :)
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