🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3427

Template linkage

#3427
From: James Robert McElroy
Date: Fri, 23 Feb 1996 18:51
79 lines
3004 bytes
A question about templates and linkage:

When dealing with template functions and template
classes, there are two different entities one has
to be concerned with:  the template definitions
and the template instantiations.  The definitions
are the code we write, e.g.

template <class T>
T fubar(T foo)
{
   // whatever
}

The instantiations are what the compiler generates:

a = fubar(someInt);        // compiler instantiates:

int fubar(int foo)
{
   // whatever
}

Now, there are four possible combinations for the linkage
of the definitions and instantiations:

  Definition      Instantiation

1. Internal         Internal
2. Internal         external 
3. External         Internal
4. External         External

With three different compilers, I've run into three different
combinations!!!  (Default behavior, without any switches):


Template functions (non-class):

		         Definition  Instantiation

1.  HP-UX C++ compiler:  External     External  
2.  Borland 3.1       :  Internal     External
3.  G++               :  Internal     Internal 

Template classes and template class functions:

1. HP-UX C++ compiler :  External      External
2. Borland 3.1        :  Internal      Internal
3. G++                :  Internal      Internal

HP manages to create external linkage for 
instantiations through the following mechanism:

When a template function or class is first
instantiated, a directory directly off the
current directory, called "ptrepository" is
created, in which all template instantiations
are stored.  This has the peculiar effect that
once you create a template instantiation in
one program, you can  call it from another
program without ever defining it in the second
program!!!  (As long as the second program is
in the parent directory of "ptrepository").

Has  the ANSI C++ committee come to any sort of
agreement on the linkage of template definitions
and instantiations?
-- 
Jim McElroy
Calif. State Univ., Chico
mcelroy@ecst.csuchico.edu
---
[ To submit articles: Try just posting with your newsreader.  If that fails,
                      use mailto:std-c++@ncar.ucar.edu
  FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <4gl22l$c7h@charnel.ecst.csuchico.edu>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: mcelroy@ecst.CSUChico.EDU (James Robert McElroy)
Newsgroups: comp.std.c++
Subject: Template linkage
Date: 23 Feb 1996 10:51:30 PST
Organization: California State University, Chico
Approved: austern@isolde.mti.sgi.com
Message-ID: <4gl22l$c7h@charnel.ecst.csuchico.edu>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: 23 Feb 1996 18:46:45 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMS4MxUy4NqrwXLNJAQH2SwH/enRsDTNB67wCUFKD+tMIZ+tpwAidAX8k
 D1JO32U/uxeZUr+XZ9mmSA8tRb9GcZDkY24aj+E1O18Q/KbTESuucg==
 =CKV3
Originator: austern@isolde.mti.sgi.com