[fpc-pascal] High() and Low() for empty dynamic arrays
Jürgen Hestermann
juergen.hestermann at gmx.de
Sat Feb 8 17:35:18 CET 2014
Am 2014-02-08 17:05, schrieb Florian Klaempfl:
> Here:
> var MyArray : array of longint;
> begin
> writeln(low(MyArray));
> writeln(high(MyArray));
> end.
> prints
> 0
> -1
Hmm.
I was under the impression that both give back zero.
But you are right.
A closer look showed that the error I got for arrays of zero length
came from the fact that I used a Cardinal type variable for the for-loop:
-------------------------------------------
var i : Cardinal;
for i := Low(MyArray) to High(MyArray) do ...
-------------------------------------------
which raises an exception when the array is empty
but works ok in all other cases.
Thanks for pointing me to my fault.
> Unfortunatly you posted not a complete example which shows the behaviour but only uncompilable code snippts.
> Post always complete examples when discussing strange behaviour.
You mean I should post thousands of code lines?
More information about the fpc-pascal
mailing list