[fpc-devel] Could FPC add the PLM "based" construct?
giuliano.colla at fastwebnet.it
Mon Nov 16 12:12:56 CET 2009
Hello FPC developers
I've been using Algol-like languages since the times of Algol '60.
In general I'm rather happy with FPC, but I miss a feature which I found
in Intel's PLM languages. I'd like to submit it to see if there's a
chance it could be introduced in FPC.
The feature is the *based* construct, which makes IMHO typed pointers
much easier to deal with. It makes the code easier to write, more
readable, and shouldn't break anything existing: it would be a language
extension, which, in my incompetent judgment, should be fairly simple to
implement. Those who don't like it could just avoid using it, and
continue the old way.
For those unfamiliar with PLM, the construct in FPC could like that:
foo: "any valid FPC Type" based Pfoo;
foo: based Pfoo "any valid FPC type";
Pfoo := APointer;
foo := Whatever;
WhateverElse := foo;
This would make Pfoo an untyped pointer, while any occurrence of foo
would be replaced by the compiler with a Pfoo^, typed unambiguously by
Multiple declarations are allowed such as:
Bfoo: byte based Pfoo;
Ifoo: Integer based Pfoo;
Pfoo := ABytePointer;
Bfoo := WhateverByte;
Pfoo := AnIntegerPointer;
WhateverInteger := Ifoo;
This becomes particularly handy when the fpc types more complex, such as
different record types.
Currently, to achieve the same result you need to write more, without
adding to readability and maintainability, but perhaps adding something
to obscurity instead:
PBfoo: PByte absolute Pfoo;
PIfoo: PInteger absolute Pfoo;
PBfoo := ABytePointer;
PBfoo^ := whateverByte;
PIfoo := AnIntegerPointer;
whateverInteger := PIfoo^;
Something of the sort is already done with objects or strings where the
pointer declaration is implicit. This construct would extend the same
logic to all other types, but with an explicit declaration of the pointer.
It would, IMHO help to get rid of some of the obscurity inherited by the
C language constructs.
This would also help to get rid, of the ambiguities (also inherited for
C) where a variable name sometimes means the value, sometimes means the
pointer, depending on context.
Whenever people agree with me, I always feel I must be wrong (O. Wilde)
More information about the fpc-devel