[fpc-devel] Limitations of static "ranged" integer types and succ/pred, and dynamic solution.
skybuck2000 at hotmail.com
Tue Dec 20 07:41:50 CET 2011
(Delphi limitation, but probably applies to free pascal as well):
Take following examples:
Tvalue = smallint;
Tvalue = word
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
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
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:
MinValue : integer;
MaxValue : integer;
Tvalue = MinValue...MaxValue;
then this type could also be used as follows:
DynamicArrayOfValues : array[Tvalue] of integer;
The user could then even fall back to old style of programming:
MinValue := 5000;
MaxValue := 10000;
DynamicArrayOfValues  := 1000;
DynamicArrayOfValues  := 2000;
^ array starts at 5000 kinda cool.
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...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-devel