Re: compiling C++ to C, was writing a compiler

Alex Colvin <alexc@TheWorld.com>
Tue, 4 Nov 2008 22:55:46 +0000 (UTC)

          From comp.compilers

Related articles
[3 earlier articles]
Re: Writing a compiler tony@my.net (Tony) (2008-10-31)
Re: Writing a compiler lkrupp@pssw.nospam.com.invalid (Louis Krupp) (2008-11-01)
Re: Writing a compiler marcov@stack.nl (Marco van de Voort) (2008-11-02)
Re: Writing a compiler lkrupp@pssw.com (Louis Krupp) (2008-11-03)
Re: Writing a compiler alexc@TheWorld.com (Alex Colvin) (2008-11-03)
Re: compiling C++ to C, was writing a compiler marcov@stack.nl (Marco van de Voort) (2008-11-04)
Re: compiling C++ to C, was writing a compiler alexc@TheWorld.com (Alex Colvin) (2008-11-04)
Re: compiling C++ to C, was writing a compiler barry.j.kelly@gmail.com (Barry Kelly) (2008-11-05)
Re: compiling C++ to C, was writing a compiler lkrupp@pssw.nospam.com.invalid (Louis Krupp) (2008-11-05)
| List of all articles for this month |

From: Alex Colvin <alexc@TheWorld.com>
Newsgroups: comp.compilers
Date: Tue, 4 Nov 2008 22:55:46 +0000 (UTC)
Organization: The World : www.TheWorld.com : Since 1989
References: 08-10-037 08-10-046 08-10-047 08-11-003 08-11-008 08-11-009 08-11-014 08-11-015 08-11-019
Keywords: C++
Posted-Date: 05 Nov 2008 18:48:12 EST

>Templates are no problem, the C++ compiler instantiates them, and writes
>them out in C code.


I believe templates involve Linker magic, since they can be used in many
compilation units. Early cfront-like compilers either generated expanded
code in each unit or resorted to #pragmas to control where templates were
actually expanded.


Consider a templated class that defines a non-inline function.
--
mac the naof
[The tricky bit about templates is avoiding duplicate expansions of templates.
You can have a linker hack that tells the linker to discard multiple code and
data sections with the same name and "expanded template" type, or you can fake
it by a pass before linking that looks at the whole program and only then
decides what to expand. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.