[fpc-devel] Limitations of static "ranged" integer types and succ/pred, and dynamic solution.

Skybuck Flying skybuck2000 at hotmail.com
Tue Dec 20 07:41:50 CET 2011


Hello,

(Delphi limitation, but probably applies to free pascal as well):

Take following examples:

Tvalue = smallint;

or
Tvalue = word

or

Tvalue = 0..5000;

^ All of these examples are quite bad in the following way:

They become very static, which makes it pretty much impossible to change 
their range at runtime.

These types are pretty much a left over from the days of turbo pascal, and 
is a reason why people switched to C, where arrays where dynamic in 
range/size.

The succ/pred functions are also pretty useless and dangerous.

If a pascal type/array using these static types needs to change to a dynamic 
type, and these succ/pred functions will lead to out of range 
problems/situations.

My recommendation for the Delphi language is to do away with these static 
types and instead change them to dynamic types, just like arrays where 
expanded with dynamic types.

Ofcourse it's nice and perhaps even required to keep these static types for 
backward compatibility but it would also be nice if these types can be 
expanded with a dynamic type, so it can be safely used with dynamic arrays 
which can be any size/range.

How this should be solved syntax-ically I don't know but I will give it a 
try below, perhaps:

var
  MinValue : integer;
  MaxValue : integer;

Tvalue = MinValue...MaxValue;

then this type could also be used as follows:

var
  DynamicArrayOfValues : array[Tvalue] of integer;

The user could then even fall back to old style of programming:

MinValue := 5000;
MaxValue := 10000;

DynamicArrayOfValues.Allocate;

DynamicArrayOfValues [5000] := 1000;
DynamicArrayOfValues [6000] := 2000;
^ array starts at 5000 kinda cool.
Etc...

Finally the pred/succ could be safely used as well:

vValue := 5000;

DynamicArrayOfValues[Pred(vValue)] := etc; // would wrap back to 6000
DynamicArrayOfValues[Succ(vValue)] := etc; // would wrap back to 5000

Just some idea's for you to explore...

Bye,
  Skybuck. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20111220/213f6cda/attachment.html>


More information about the fpc-devel mailing list