This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Question: possible feature for C++
- From: "Kaz Kylheku" <kaz at zeugmasystems dot com>
- To: "Dima Sorkin" <dima dot sorkin at gmail dot com>, <gcc-help at gcc dot gnu dot org>
- Cc: "Peter Rybin" <peter at rybin dot spb dot ru>
- Date: Mon, 4 Dec 2006 10:01:45 -0800
- Subject: RE: Question: possible feature for C++
On December 5, 2006 Dima Sorkin wrote:
> On 12/4/06, Peter Rybin wrote:
> > To let me completely forget about header files and
> > ordering of my declarations.
> Hi.
>
> I think this will break the ability of compiling C++ modules
> separately,
> as compiler will have to see the whole code ahead.
You might want to look at how some other languages handle this, like
Modula 2/3, Ada ...
Instead of seeing the whole code, the compiler sees some fraction of the
code which is designated as the interface.
In C++, we fraction off that part into a separate file and use text
inclusion. In these other languages, there is a more disciplined
approach whereby a module expresses a dependency on the other one, and
the compiler extracts the interface fraction of the module.
The nice thing is that because the data is structured in this way, you
can optimize it cleanly. For instance, the compiler can take the
interface fraction of a module, and compile it into a binary form. Then
when that module is used during the compilation of hundreds of other
modules, no lexical analysis or parsing has to take place. The compiler
loads (or refers to an already loaded) binary structure.
Similar things have been done for languages based on text inclusion,
like the ``precompiled headers'' in Microsoft's compiler. Without the
underlying structure which delimits the interfaces as objects, it
doesn't work particularly well. You get problems with broken
dependencies so that precompiled headers are not refreshed, etc.