Article View: comp.std.c++
Article #2910Re: ANSI compiant explicit template instantation
From: Bill Leonard
Date: Thu, 07 Dec 1995 21:36
Date: Thu, 07 Dec 1995 21:36
65 lines
4056 bytes
4056 bytes
In article <9512071347.AA29456@lts.sel.alcatel.de>, James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de> writes:
> If you use the template, it is instantiated. You don't need to force
> instantiation. If you don't use it, why do you want to instantiate
> it? Just to have extra code (which is never called) in your
> application.
To me, the issue would not be instantiating a template that is never used,
but rather to control exactly *where* and *when* the instantiation occurs.
For reasons of building shared libraries, or even unshared libraries that
are going to be used by multiple programs, one may wish to know exactly in
what object module a given template instantiation is placed.
Along with a mechanism for explicit instantiation, I would also want a way
to tell the compiler to *never* instantiate automatically. One of the
scary things about the current template mechanism is that I can
accidentally instantiate a template and I'll never know it, except where it
causes my program to break. I'd much rather explicitly instantiate
everything, then I know that any accidents will show up as link-time
errors.
Another justification for this is controlling the compile-time options when
an instantiation is compiled. I may decide that a particular template
needs more (or less) optimization. Many modern compilers have tons of
options for controlling optimization that, for best performance, have to be
tuned. They also have lots of options that affect compile time that could
make the difference between hours of compilation or seconds. (A colleague
of mine just implemented a new compiler option that made a rather bizarre
machine-generated program go from 17 hours of compile time to 1 minute!)
Other compilation options are also important. Some systems require special
code generation techniques if a module is going to reside in a shared
library. How do I get that to happen, especially if the code that uses the
template is *not* destined for a shared library?
How do I know what options were used to compile an instantiation if I don't
even know when it will be compiled?
I could go on, but I think you get the idea.
Some compilers now existing have options and/or pragmas for doing this.
The question is whether that's sufficient or whether some or all of it
should be standardized. I don't honestly know -- I just wanted to give a
user's view of why this feature is desirable.
--
Bill Leonard
Harris Computer Systems Corporation
2101 W. Cypress Creek Road
Fort Lauderdale, FL 33309
Bill.Leonard@mail.hcsc.com
These opinions and statements are my own and do not necessarily reflect the
opinions or positions of Harris Computer Systems Corporation.
------------------------------------------------------------------------------
There's something wrong with an industry in which amazement is a common
reaction to things going right.
"Hard work never scared me. Oh, sure, it has startled me from a distance."
-- Professor Fishhawk
------------------------------------------------------------------------------
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<4a7m4q$8g@hawk.hcsc.com>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<4a4io5$s0v@cronkite.seas.gwu.edu> <9512071347.AA29456@lts.sel.alcatel.de>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: bill@amber.ssd.hcsc.com (Bill Leonard) Newsgroups: comp.std.c++ Subject: Re: ANSI compiant explicit template instantation Date: 7 Dec 1995 21:36:29 GMT Organization: Harris Computer Systems, Ft. Lauderdale FL Approved: clamage@eng.sun.com (comp.std.c++) Distribution: world Message-ID: <4a7m4q$8g@hawk.hcsc.com> References: <4a4io5$s0v@cronkite.seas.gwu.edu> <9512071347.AA29456@lts.sel.alcatel.de> Reply-To: Bill.Leonard@hawk.hcsc.com NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: amber.ssd.hcsc.com Content-Length: 3113 X-Lines: 61 Originator: clamage@taumet