[fpc-devel] "Friend" classes?

DrDiettrich drdiettrich at compuserve.de
Thu Mar 24 09:02:30 CET 2005

Florian Klaempfl wrote:

> >>C++ creates one monster module in this case as well.
> >
> >
> > I disagree. Neither the declarations (interface, header files) nor the
> > definitions (implementation, code modules) must reside in one file.
> How the sources are splitted doesn't matter. The compiler handles it as one file
> and creates one object module. The compiler even doesn't see that the files are
> splitted, the preprocessor concats everything.

Please let me quote the originial statement:

>>In porting C++ code to Pascal I often stumbled into circular unit
>>references. Then the only solution is a monster unit, that implements
>>all the related classes at once, where the C++ implementation can be
>>split into appropriate modules.

In one case I had about 10 C++ modules, which implemented one class
each. These modules can be compiled separately, into the same number of
object files.

In Pascal I had to merge all these modules into an single unit, due to
circular unit references. This monster unit then compiles into one
object file, of course.

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}!

> Units are a higher level concept than the include files of C++ but units can
> often but not necessarily reflect the include file structure.

There exist many kinds of concepts, with regards to the relationship
between declarations (interfaces) and definitions (implementations). In
C/C++ both are separated and strictly unrelated, in Modula both are
separated into strictly related files, in Pascal or Java both are
combined into single unit (class) files. I cannot see any "levels" in
these concepts. Adding namespaces results in a 3D model, of
declarations, namespaces, and implementations.

For the compound Pascal units, the most important *difference* is the
required implementation of everything, what's declared in the interface
section of an unit, in the implementation section of the *same* unit.
This requirement leaves no room for inconsistent sets of interfaces
(header files) and implementations (source modules).

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


More information about the fpc-devel mailing list