www.digitalmars.com         C & C++   DMDScript  

c++ - template instantiation

reply Christof Meerwald <cmeerw web.de> writes:
In the following test-case, the template function isn't instantiated (linker
complains with "Symbol Undefined ?f  YAHH Z (int cdecl f(int ))"):

  template<class T> int f(T a);

  int main(int argc, char *argv[])
  {
    int a = 0;
    return f(a);
  }

  template<class T> int f(T a)
  {
    return 0;
  }


and DM doesn't support explicit template instantiation, e.g.

  template<class T>
  struct A
  {
    void f()
    { }
  };

  template A<int>;


bye, Christof

-- 
http://cmeerw.cjb.net                          Jabber: cmeerw jabber.at
mailto cmeerw at web.de                   ICQ: 93773535, Yahoo!: cmeerw

...and what have you contributed to the Net?
Oct 15 2001
parent reply John Fletcher <J.P.Fletcher aston.ac.uk> writes:
Christof Meerwald wrote:

 In the following test-case, the template function isn't instantiated (linker
 complains with "Symbol Undefined ?f  YAHH Z (int cdecl f(int ))"):

   template<class T> int f(T a);

   int main(int argc, char *argv[])
   {
     int a = 0;
     return f(a);
   }

   template<class T> int f(T a)
   {
     return 0;
   }

 and DM doesn't support explicit template instantiation, e.g.

   template<class T>
   struct A
   {
     void f()
     { }
   };

   template A<int>;

 bye, Christof

 --
 http://cmeerw.cjb.net                          Jabber: cmeerw jabber.at
 mailto cmeerw at web.de                   ICQ: 93773535, Yahoo!: cmeerw

 ...and what have you contributed to the Net?
You don't say what compiler options you used. When I get messages like this I retry with -XD added. John
Oct 16 2001
parent reply "Walter" <walter digitalmars.com> writes:
Yes, -XD will make it work with the existing compiler, but I wanted to fix
it so it worked automatically. -Walter

John Fletcher wrote in message <3BCBF5E9.83FE7752 aston.ac.uk>...
Christof Meerwald wrote:

 In the following test-case, the template function isn't instantiated
(linker
 complains with "Symbol Undefined ?f  YAHH Z (int cdecl f(int ))"):

   template<class T> int f(T a);

   int main(int argc, char *argv[])
   {
     int a = 0;
     return f(a);
   }

   template<class T> int f(T a)
   {
     return 0;
   }

 and DM doesn't support explicit template instantiation, e.g.

   template<class T>
   struct A
   {
     void f()
     { }
   };

   template A<int>;

 bye, Christof

 --
 http://cmeerw.cjb.net                          Jabber: cmeerw jabber.at
 mailto cmeerw at web.de                   ICQ: 93773535, Yahoo!: cmeerw

 ...and what have you contributed to the Net?
You don't say what compiler options you used. When I get messages like
this I
retry with -XD added.

John
Oct 16 2001
parent reply Christof Meerwald <cmeerw web.de> writes:
On Tue, 16 Oct 2001 11:42:43 -0700, Walter wrote:
 Yes, -XD will make it work with the existing compiler, but I wanted to fix
 it so it worked automatically. -Walter
Thanks for fixing it.
 and DM doesn't support explicit template instantiation, e.g.
and the '-XI' command line option doesn't seem to work for class templates.
   template<class T>
   struct A
   {
     void f()
     { }
   };
If I compile it with 'sc -c -cod "-XIA<int>"' no code for the instantiation is generated. bye, Christof -- http://cmeerw.cjb.net Jabber: cmeerw jabber.at mailto cmeerw at web.de ICQ: 93773535, Yahoo!: cmeerw ...and what have you contributed to the Net?
Oct 16 2001
parent reply "Walter" <walter digitalmars.com> writes:
The XI is a holdover from the bad old days before comdat's. Do you need it?

"Christof Meerwald" <cmeerw web.de> wrote in message
news:9qi0v7$2gvh$1 digitaldaemon.com...
 On Tue, 16 Oct 2001 11:42:43 -0700, Walter wrote:
 Yes, -XD will make it work with the existing compiler, but I wanted to
fix
 it so it worked automatically. -Walter
Thanks for fixing it.
 and DM doesn't support explicit template instantiation, e.g.
and the '-XI' command line option doesn't seem to work for class
templates.
   template<class T>
   struct A
   {
     void f()
     { }
   };
If I compile it with 'sc -c -cod "-XIA<int>"' no code for the
instantiation
 is generated.


 bye, Christof

 --
 http://cmeerw.cjb.net                          Jabber: cmeerw jabber.at
 mailto cmeerw at web.de                   ICQ: 93773535, Yahoo!: cmeerw

 ...and what have you contributed to the Net?
Oct 16 2001
parent Christof Meerwald <cmeerw web.de> writes:
On Tue, 16 Oct 2001 15:12:08 -0700, Walter wrote:
 The XI is a holdover from the bad old days before comdat's. Do you need it?
I would prefer the standard C++ explicit template instantiation. STLport's I/O stream library makes heavy use of it (I was just looking for an alternative). bye, Christof -- http://cmeerw.cjb.net Jabber: cmeerw jabber.at mailto cmeerw at web.de ICQ: 93773535, Yahoo!: cmeerw ...and what have you contributed to the Net?
Oct 17 2001