[fpc-devel] Could FPC add the PLM "based" construct?

David W Noon david.w.noon at ntlworld.com
Mon Nov 16 13:52:04 CET 2009


On Mon, 16 Nov 2009 12:17:23 +0100, Micha Nelissen wrote about Re:
[fpc-devel] Could FPC add the PLM "based" construct?:

> Giuliano Colla wrote:
> > var
> >   Pfoo: pointer;
> >   foo: "any valid FPC Type" based Pfoo;
> > or
> >   foo: based Pfoo "any valid FPC type";
> > .....
> >   Pfoo: pointer;
> >   PBfoo: PByte absolute Pfoo;
> >   PIfoo: PInteger absolute Pfoo;
> 
> I don't see the difference between "based" and absolute, except order
> of keywords?

The "based" keyword actually comes from PL/I, which Intel used as the
basis for PL/M.

The way based variables work is that they are always accessed via a
pointer, but the pointer is always type-neutral.  This means that the
access to the addressed storage location is determined not by the
pointer, but by the based variable (usually a structure).

This, in turn, means that one can declare multiple structures associated
with just a single pointer, each causing the compiler to generate code
specific to that structure.  The benefit is that there can be some
indicator that tells the application *at run time* what type of
structure the pointer is addressing, and the appropriate code to access
the data can be executed.

The synopsis is that an untyped pointer becomes like a hardware "base
register", which is the way pointers are meant to be.

Note that PL/I also has type-associated pointers, called a "handle" for
the associated type.  These behave like Pascal pointers, in that they
are rather safer, but far less flexible.
-- 
Regards,

Dave  [RLU #314465]
=======================================================================
david.w.noon at ntlworld.com (David W Noon)
=======================================================================



More information about the fpc-devel mailing list