Porting from Dec Pascal to GPC

Frank Heckenbach ih8mj at fjf.gnu.de
Sat Mar 5 02:52:16 CET 2005


Waldek Hebisch wrote:

> D. Wood wrote:
> > I produced the attached document when converting a large DEC
> > Pascal simulation to gpc (under Linux) some years ago.  We can
> > still run our code on both VMS and gpc. I think it should help
> > get round most issues you may come across.
> > 
> > It leaves a fair bit of manual editing but by adopting a
> > conversion checklist, the manual process is straightforward.
> 
> A little nitpick: in principle GPC should run on VMS. So when you 
> write `Linux REAL defaults to DOUBLE.' it should be `GPC REAL defaults
> to DOUBLE.' (even on VMS GPC would use DOUBLE as REAL). The same in
> few other places. 

Indeed. I haven't seen anything Linux specific in the document (with
one unnecessary exception, see below), so such names suggest an
unnecessary system restriction.

> Second remak: GPC supports conditional compilation, macros and include
> files. Using those features you should be able to avoid extra preprocessing
> (I assume that DEC Pascal treats {$...} construct as a comment). 

Yes -- this should avoid conversion scripts and make it easier to
work on a single source base.

Some other points:

: Add a space between unformatted integers in a write statement.
:         GNU Pascal doesn't assume a default field width for integers so they
:         merge when output.

The `field-widths' directive/option can change this.

: In modules, make global string definitions local.  If required by global
: routines within the module, pass them as parameters.  Alternatively, avoid
: the need to use global string variables defined within a module.
:         A bug in GNU Pascal means that strings defined globally by a  module
:         can unexpectedly become  unassignable  (ie.  they  maintain  a  null
:         length even when assigned a value).

This bug has long been fixed meanwhile, BTW.

: {*V*} a:= ZERO;        {*V*} a : array [1..3] of double:= ZERO;
:
:
:         {*L*} zero(a);       {*L*} a : array [1..3] of double:= (0,0,0);
:
:         DEC Pascal can use this assignment to zero/null records  and  arrays
:         in declaration sections as well as in the main  body  of  the  code.
:         Through  <os_linux.h>  ,   zero(a)    is   mapped   to   DEC_zero(a,
:         sizeof(a)), a procedure  defined  in  unit  OS_linux   which  clears
:         memory at the address of parameter a.   However this cannot be  used
:         to replace  :=ZERO  in the declaration section.  Small arrays can be
:         zeroed with 0's.  e.g. for a 3-component array of  reals,  use    :=
:         (0,0,0)   and for complex components use   :=( (0,0),  (0,0),  (0,0)
:         ).  Large arrays must be initialised in the body of  the  code  with
:         zero(a).

Recently (since 20041017) GPC supports EP initializers which can be
written independent of the array size:

var
  a : array [1..3] of double value [otherwise 0];

: Replace  SYS$OUTPUT  with  /dev/stdout.
: Replace  SYS$INPUT  with  /dev/stdin.

Actually better replace both with '-' or '' (empty string). These
are recognized as standard input/output by GPC (dependent on whether
the file is opened for reading or writing). Whereas `/dev/stdout'
etc. are just symlinks on Linux (and perhaps other Unix compatbile
systems), and probably don't work elsewhere.

:    {$define uint cardinal}

Usually it's better to declare such things as types (i.e.
`type uint = Cardinal;'). Defines are not scoped, so e.g. affect the
use of such identifiers locally, or in record fields etc., sometimes
leading to mysterious error messages.

Frank

-- 
Frank Heckenbach, frank at g-n-u.de, http://fjf.gnu.de/, 7977168E
GPC To-Do list, latest features, fixed bugs:
http://www.gnu-pascal.de/todo.html
GPC download signing key: ACB3 79B2 7EB2 B7A7 EFDE  D101 CD02 4C9D 0FE0 E5E8




More information about the Gpc mailing list