Re: namespaces and main()

From: poiuz24 (poiuz24_at_web.de)
Date: 07/26/04


Date: 26 Jul 2004 03:17:32 -0700


> I for one would love something along the lines of:
> #import "otherclass.cpp"
> and
> #import <vector>
> etc.
> I'm sure that something like this could be made to work, it's just a
> matter of someone writing it and proving it.

yes, i'd love that too .. actually, i thought along very
similar lines: import "otherclass"

that is, not the preprocessor, but the compiler would handle
'import' and no specification of file extension, since object
file extensions may be platform specific (on a *nix system, above
would make the compiler read type information for OtherClass
from "otherclass.o")

> >it becomes clearer and clearer to me that the real legacy are the
> >object file formats used to communicate between compiler and linker
>
> Indeed. C++ was specifically designed so that it could be linked using
> a traditional linker. Templates slightly damaged that, and the best
> solution would be to bite the bullet and either go down the pre-linker
> route or use more intelligent linkers.

aeh, what is the "pre-linker route"? didn't heard of that one yet ..

> Sadly C++ was designed with multiple preprocessed translation units
> very firmly in mind. Changing it to use something more like "modules"
> is not going to be easy, but I think it would be worth the effort.

a module system that integrates with the build system .. absolutely!

i've spent some time trying to figure out what would be needed.
i came to the conclusion that one would need to bring the
object file format much closer to the compiler middle in a computer
science sense, that is closer to the Abstract Sytntax Tree.

a new object file format containing full static type information for
exported types would be needed. what does "full static type inf." mean?

e.g. for exported non-inline, non-template, non-member functions:

 - the fully namespace qualified function name
 - the function signature

so far so good. this could be done pretty ad-hoc. but what is
"full static type inf." for an exported template function e.g.

    template<typename T> T fun (const T& x);

i would argue that full static type information in this case
included the function body. if so, that would require a new
object file format to be powerful enough to express function
bodies. that could be done at the Abstract Syntax Tree (AST)
level. in other words, a sufficiently powerful object file
format would be similar to a persistent file format for
C++ ASTs. when compiling a translation unit, the compiler would
produce an object file that contains native code + those parts
of the AST for the current translation unit, that describe exported
types. compiling another translation unit importing a module
would make the compiler not start with the empty AST for the
translation unit, but with an AST prefilled from the AST parts
embedded in and read from all imported modules.

in a sense, this is perhaps roughly similar to preparsed
headers but without the headers

i'm sure this is no new idea but must have been proposed
already. what's the catch? would such a module system "deliver"?



Relevant Pages

  • Re: Static vs. Dynamic typing (big advantage or not)---WAS: c.programming: OOP and memory management
    ... > The problem is static type checking is a very weak form of testing. ... Static language features, including static typing are ... not impediments to incremental development and early testing. ... The compiler checks for a lot of errors, ...
    (comp.object)
  • Re: Static vs. Dynamic typing (big advantage or not)---WAS: c.programming: OOP and memory management
    ... > The problem is static type checking is a very weak form of testing. ... Static language features, including static typing are ... not impediments to incremental development and early testing. ... The compiler checks for a lot of errors, ...
    (comp.programming)
  • Re: External RAMdisk
    ... battery backed RAM disk. ... I goosed the KayPro II up to 5 MHz, ... People used to tell me that this wasn't much of a test, because all I was measuring was the overhead time of the compiler and other tools. ... To put things in perspective, running this on a VAX 11/780, with BSD Unix, took 20 seconds, and generated a 20k object file. ...
    (comp.os.cpm)
  • Re: What a translation unit is.
    ... >>So therefore it only makes sense to me that the most usefull translation ... > But let's keep assuming the traditional compiler system. ... >>something inbetween states of tranlation then the object file is most ... >>The source file is a unit to be translated. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: namespaces and main()
    ... >> an object file for a translation unit which contains enough ... >> information for the linker to check if any exported type information ... You completely ignore that the main use of a header ... if a compiler would produce object ...
    (comp.lang.cpp)