[fpc-devel] "Friend" classes?

Marco van de Voort marcov at stack.nl
Sat Mar 26 21:42:13 CET 2005

> Micha Nelissen wrote:
> > > Perhaps you missed that in C/C++ the preprocessor is typically (99.999%)
> > > used to include header files, not source files. This is comparable to
> > > Pascal "uses", not to {$Include}!
> > 
> > What's the difference between a 'header' file, and a source file ? Header > files often contain template classes with inline implemented methods.
> > Preprocessor is used also for macros.
> The definitions of templates, inline procedures or macros do not
> immediately contribute to the size of a compiled module, only when they
> are *used* in code modules.

That goes for all routines.

> > Please look again at 'uses', it works on a more abstract level than just
> > recompiling all units depended on, it's where the speed of compiling pascal
> > comes from.
> In comparison with C/C++, "uses" summarizes the #include of header files
> and the dependency checks of Make.

The important difference (in TP/Delphi/FPC) is that preprocessor state
doesn't follow USES statements. 

That allows the compiler to auto-find the compilation order..

> Many properties make Pascal compilers faster than C/C++ compilers. The
> effect of "uses" is equivalent to C/C++ precompiled header files.

The effect of units is that it is a lot safer (more guaranteed) and easier
to implement that precompiled header files, and auto-building is also a lot
easier (not requiring explicit manual compile order enforced)

> > > The only *disadvantage* of units are the current Pascal compilers, which
> > > cannot handle circular unit references :-(

It could in theory deal with some forms of circular records. Specially in
the case of e.g. classes.

Just recompile till CRCs don't change anymore. This allows units that
circularly import eachother, but have no real circular dependancy of types
to compile. Or even if the circular reference only involves types of which
the sizes are known (like class etc types that are only 4 bytes).

However it is of course questionable if it is worth the trouble to implement
this, and make it bullet proof. Maybe somebody who does graph theory as 
a hobby?

> > No, it's an advantage: it makes the code and design clearer, plus it
> > increases the speed of compilation a *lot*.
> I wouldn't call a design clearer when it requires to implement most of a
> project in a single unit :-(

Why would you have to ?
> I also doubt about the speed increase, as long as nobody tried to write
> an Pascal compiler that can handle circular unit references.

I fail to see the connection between what the speed increase has to do
with not handling circular reference systems?

IIRC TP could handle mild circular references and so can FPC. I don't know
if this is still the case.

More information about the fpc-devel mailing list