Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > templates being exported

Reply
Thread Tools

templates being exported

 
 
Rahul
Guest
Posts: n/a
 
      01-13-2008
Hi Everyone,

I was looking at the link,

http://www.comeaucomputing.com/4.0/d...an/export.html

and it looks like the basic purpose of exporting templates is make
sure that they are visible in other compilation units for the compiler
to perform instantiation... is this because template instantiation is
something done at compile time by the compiler?

had template instantiation been done at linking time, would extern
keyword have worked? I understand that it really doesn't make sense
for the linker to do, i'm just trying to understand the reason why
export keyword came into picture...

Thanks in advance!!!
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      01-13-2008
On Jan 13, 12:52 pm, Rahul <(E-Mail Removed)> wrote:
> I was looking at the link,


> http://www.comeaucomputing.com/4.0/d...an/export.html


> and it looks like the basic purpose of exporting templates is make
> sure that they are visible in other compilation units for the compiler
> to perform instantiation...


No. The main purpose of exporting templates is to prevent their
being parsed in the context of the user. The implementation of
an exported template will not be affected by symbols (nor
macros) that the user might introduce. A second purpose is to
reduce the time of recompilations if the template implementation
is modified.

> is this because template instantiation is something done at
> compile time by the compiler?


When the template instantiation occurs is not specified; I've
used compilers which do it at compile time, and compilers which
do it at link time.

> had template instantiation been done at linking time, would
> extern keyword have worked? I understand that it really
> doesn't make sense for the linker to do, i'm just trying to
> understand the reason why export keyword came into picture...


The reason is basically because some people wanted to be able to
use templates in large applications; they didn't want the
template implementation to be subject to the aleas of whatever
else a user might have defined in the file using it. Basically,
they wanted templates to "work", just like any other class or
function "works".

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
exported templates in icpc ciccio C++ 20 01-09-2008 07:52 PM
how to Specializations of function Templates or Overloading Function templates with Templates ? recover C++ 2 07-25-2006 02:55 AM
Templates templates templates JKop C++ 3 07-21-2004 11:44 AM
filename in exported excel file =?Utf-8?B?endlbmc=?= ASP .Net 3 04-09-2004 07:46 PM
Xml exported text Bob Perl 0 03-05-2004 11:25 PM



Advertisments