Am 2016-04-16 um 19:39 schrieb Dmitry Boyarintsev:
> The problem is with using "unsigned" as an index (rather than zero- vs one- 
based arrays)
> Take a while loop as an example, where index can change multiple times.
> Current solution:
> while i>=0 do
>   if cond then dec(i);
>   dec(i);
> end;
> Unsigned index solution
> while i>=0 do
>   if cond then if i>0 then dec(i);
>   if i>0 then dec(i);
> end;
> Without these checks, unsigned integer would loop over to $FFFFFFFF and will 
continue.

That looks to my like an very artifical example.
I never came over a loop where I (conditionally)
decremented the index twice.
But of course, if you have such a case, then you
can only use signed intergers.

But in all the following cases I could used an unsigned
integer (when having 1-based arrays):

1.) for i := low(array) to high(array)

2.) repeat or while loops where the index is in- or
decremented by a maximum of 1 (which IMO is the case
in 99,9% of all such loops).

3.) When storing an array index into a variable for later use.

Nevertheless, using unsigned integers was only one aspect
of 1-based arrays. The main one for me was, that it is
much more intuitive and therefore less error prone.
I already often had errors when calculating indices for 0-based arrays.

And why was a directive implemented to use 0-based indices
even for strings but none for 1-based indices in dynamic arrays?
IMO the latter would be much more desired.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to