According to richard.kerry@quantel.com:
Hello, Could somebody please either :
- Direct me to -
info -f gpc -n "Source structures"
at least explains how to use Units, and in
info -f gpc -n "Extensions"
you can read about Modules. This second documentation is somehow outdated; many things which are mentioned as missing features are implemented meanwhile.
or : 2. Send me - a comprehensive explanation of separate compilation using gpc, including examples that clearly show which bits are in different files and how the other bits pick up their definitions. And also including any alternate/non-standard/old-fashioned techniques that are still usable.
Coming below.
I am working on a very large project, developed using Oregon Pascal. The separate compilation is done by each module (eg fred.pas) having a header file (eg fred.def) containing all the procedures, functions, types and constants it wishes the rest of the world to know about. All the routines in the header are 'external'. The modules all contain their own global variables; if any need to share, this is done by access procedures, or records shared via pointers. There is no module/unit/import/export/interface/implementation system involved. The modules are compiled individually, using #include (%include in Oregon) to
You can also use (*$i Foo *) or (*$include "foo.pas" *) or (*$include <foo.pas> *).
pick up any external definitions and references required, and then linked. I want to mechanically translate all these modules to gpc, so I'd prefer a mechanism, if there is more than one available, that uses a structure as similar as possible to the one we are currently using.
The closest approximation to Oregon Pascal (as you describe it) which is currently possible with GNU Pascal is to use the "somewhat simpler GPC modules" described in `info -f gpc -n Extensions'. When `foo.pas' reads;
Module Foo;
Var x: Integer;
Procedure y;
begin (* y *) writeln ( 'y' ); end (* y *);
end.
Then your `foo.def' can be
(* foo.def *)
Var x: __external__ Integer;
Procedure y; External;
and $including `foo.def' into the main program and linking with `foo.o' will have the desired effect ... uh - sh** (sorry!) it does not work! :-( :-(
While implementing other things I threw away this one. The reason is that this feature turned into a bug when using Extended Pascal Modules or UCSD/Borland Pascal Units.
Okay, this "GPC specific module" is very close to yet another type of Module defined in the PXSC standard. The only difference is that PXSC wants the reserved word `global' in front of each declaration that is to be exported. That's certainly more reasonable than to export just everything (like GPC did until February 1997 or so). It is planned to implement these PXSC modules into GPC.
So you can either wait until GPC will have PXSC modules and then use
Module Foo;
Global Var x: Integer;
Global Procedure y;
begin (* y *) writeln ( 'y' ); end (* y *);
end.
---
(* foo.def *)
Var x: __external__ Integer;
Procedure y; External;
---
Program Bar;
(*$I foo.def *)
...
or use UCSD/Borland-style Units
Unit Foo;
Interface
Var x: Integer;
Procedure y;
Implementation
Procedure y;
begin (* y *) writeln ( 'y' ); end (* y *);
end.
---
Program Bar;
uses Foo;
...
or Extended Pascal Modules
Module Foo Interface;
Export FooStuff = ( x, y );
Var x: Integer;
Procedure y;
end.
---
Module Foo Implementation;
Procedure y;
begin (* y *) writeln ( 'y' ); end (* y *);
end.
---
Program Bar ( Input, Output, Whatever );
Import FooStuff;
...
Hope this helps,
Peter
Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [971005] maintainer GNU Pascal [971001] - http://home.pages.de/~gnu-pascal/ [971005]