[fpc-pascal]Interface-only units (was: shared libraries interface)

Michael Van Canneyt michael.vancanneyt at wisa.be
Fri Aug 2 12:41:38 CEST 2002


On Fri, 2 Aug 2002, Jonas Maebe wrote:

>
>
> On Fri, 2 Aug 2002, Full_Name wrote:
>
> > One other point.. surely the interface is there just for the
> > convenience of the developer - like a C header file.
>
> No, it's mainly to guarantee portability between different compiler
> versions. The problem is that the ppu files are compiler versino
> dependent, so if you want to distribute a unit without the source, you
> have to re-distribute it every time a new compiler version is released (if
> the ppu format has changed at least), which is not very nice. With the
> interface-only units, you distribute an object file and an interface and
> people can use the unit, no matter which versio of the compiler they use
> (in theory at least :)

I don't see the use of such a construct:
A. If the internal naming conventions of the compiler change,
   chances are that the object file is useless anyway.
B. If the internal alignment rules for constants, sets, records and
   I don't know what change, then you're stuck as well.
Since with a new compiler version, you are not guaranteed that these
things have not changed, this rather defeats the purpose of the unit as
you will be forced to redistribute anyway.
So I see no real use for a 'interface-only' unit.

What is more, you can easily make o an 'interface-only unit' now. The
easy way is to have all functions in a separate object file and create
a unit that just contains the needed definitions.
This is already possible as follows:

-----------------------------------------------------------------------
unit something;

interface

{$l realsomething.o} // Contains actual implementation.

Procedure Dosomething; External name 'DoSomething';

Implementation

end.
-----------------------------------------------------------------------

The object file can be created compiling the following:

-----------------------------------------------------------------------
unit realsomething;

interface

Procedure Dosomething; [alias: 'DoSomething'];

Implementation

Procedure DoSomething;

begin
  DoSomething
end;

end.
-----------------------------------------------------------------------

The something.pp unit can be distributed, together with the
realsomething.o file. No compiler support needed.

But this will still suffer from the same problem (B) as the
'interface-only' unit.

Michael.





More information about the fpc-pascal mailing list