templates being exported

Discussion in 'C++' started by Rahul, Jan 13, 2008.

  1. Rahul

    Rahul Guest

    Hi Everyone,

    I was looking at the link,

    http://www.comeaucomputing.com/4.0/docs/userman/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!!!
     
    Rahul, Jan 13, 2008
    #1
    1. Advertising

  2. Rahul

    James Kanze Guest

    On Jan 13, 12:52 pm, Rahul <> wrote:
    > I was looking at the link,


    > http://www.comeaucomputing.com/4.0/docs/userman/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:
    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
     
    James Kanze, Jan 13, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob

    Xml exported text

    Bob, Mar 5, 2004, in forum: Perl
    Replies:
    0
    Views:
    414
  2. =?Utf-8?B?endlbmc=?=

    filename in exported excel file

    =?Utf-8?B?endlbmc=?=, Apr 9, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    617
    Scott
    Apr 9, 2004
  3. JKop
    Replies:
    3
    Views:
    492
  4. recover
    Replies:
    2
    Views:
    831
    recover
    Jul 25, 2006
  5. ciccio

    exported templates in icpc

    ciccio, Jan 7, 2008, in forum: C++
    Replies:
    20
    Views:
    788
    Pete Becker
    Jan 9, 2008
Loading...

Share This Page