 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
rsergeant Guest
|
Posted: Mon May 21, 2007 7:44 pm Post subject: C++ parsers and Template instantiation |
|
|
Hi all,
First of all, if this is way of topic or if there is a better place to
ask, sorry for the noise.
I think template instantiation happens as part of parsing the C++
source file. Probably in a second pass over the source code, but still
as part of the parsing process. The reason why I think so, is because
new types are created when templates are instantiated so some sort of
parsing is needed.
Is my assumption correct? Or is template instantiation a whole
different kind of thing?
I've searched in a number of books, but found nothing that mentions
compilers that generate new types (either by template instantiation or
otherwise). If someone can point me to this kind of information I'd be
happy too.
Thanks in advance,
Kind regards,
Roel Sergeant.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
Guest
|
Posted: Tue May 22, 2007 12:11 am Post subject: Re: C++ parsers and Template instantiation |
|
|
On May 21, 9:44 pm, rsergeant <rserge...@gmail.com> wrote:
| Quote: | Hi all,
I think template instantiation happens as part of parsing the C++
source file. Probably in a second pass over the source code, but still
as part of the parsing process. The reason why I think so, is because
new types are created when templates are instantiated so some sort of
parsing is needed.
|
Parsing is a word with a very specific meaning. Yes, logically
templates
require a second step, but not a second parsing step. Basically in
parsing
the compiler takes a source file and turns it into a list of tokens
with
some basic meaning attached to it : identifier, keyword, number.
Thanks to keywords like 'typename' and 'template' the parsing phase
can
assign meaning to identifiers even before instantiating templates,
even
in difficult template cases.
In later phases, higher-level structures are created. No longer is
A<T>
a type, but the compiler will figure out what members the type has.
Only with 'export' does the compiler use a real second phase of
template
compilation, when it discovers during linking it misses template
instantiations. But IIRC all export-supporting compilers can reuse the
output from the parse phase for that.
HTH,
Michiel Salters
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|