[fpc-devel] Limitations of static "ranged" integer types and succ/pred, and dynamic solution.
JeLlyFish.software at gmx.net
Fri Dec 23 00:13:42 CET 2011
On Tue, 20 Dec 2011 07:41:50 +0100, Skybuck Flying
<skybuck2000 at hotmail.com> wrote:
> (Delphi limitation, but probably applies to free pascal as well):
You have a very interesting definition of "limitation", but 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.
I can't see any reason why you would even want to change a range during
runtime. After all, there usually was a pretty good reason why you applied
a range the first time, otherwise you would have used Integer directly.
> 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.
As if the only purpose of range types is to index dynamic arrays.
> Ofcourse it's nice and perhaps even required to keep these static types
> 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
> which can be any size/range.
In that case you just need one type: InfiniteInteger (or maybe call it
UnconstrainedInteger), where it's bit size changes during runtime up to
the point where the computer memory is exhausted. So, instead of getting
Range-Check errors, you get memory allocation failures trying to allocate
an integer requiring 2**128 bits. :->
> MinValue : integer;
> MaxValue : integer;
> Tvalue = MinValue...MaxValue;
> then this type could also be used as follows:
> DynamicArrayOfValues : array[Tvalue] of integer;
Umm, and what shall happen, if I change MinValue somewhere inbetween? The
array size and/or index range shall magically change with it?
And why would that be better than a (more) simple
Dynamic : array[MinValue .. MaxValue] of Integer;
TValue = Low (Dynamic) .. High (Dynamic);
The array and the type you're indexing it with are tied to each other
way, so there's no point in changing only one of it. Or, to express it
differently: As long as you don't know the size of the array you also don't
know the range of the index type - and vice versa.
Well, considering that the latter is (to some extent) already available in
current compiler, your proposal is IMO quite useless.
Or - may I speak freely, sir? ... Then, I think, it's bullshit.
More information about the fpc-devel