[fpc-pascal] dynamic array contents and system.move

José Mejuto joshyfun at gmail.com
Sun Apr 25 20:15:10 CEST 2010


Hello FPC-Pascal,

Sunday, April 25, 2010, 6:29:26 PM, you wrote:

>> I think there is a great difference between normal arrays and dynamic ones
JH> Yes, but it should not be like that. If you first declare a
JH> static array and then decide to make it a dynamic array then *no*
JH> code change should be required.  But now it is for move and
JH> fillchar.

And many more are not identical:

A: array of integer;
B: array of integer;

setlength(A,1);
A[0]:=12;
B:=A;
A[0]:=13;
writeln(B[0]);

Which values will be printed ? 12 or 13 ?

>> is OK, but in dynamic arrays it should be:
>> A: array of integer;
>> SetLength(A,2);
JH> Why change the array length here? The array has a length
JH> already. What if the array had 10 elements before? 

Because if had defined the array in the line just before "SetLengh"
and I need to give it a size.

>> move (a[0],somewhere^,4);
>> move (a[1],(somewhere+4)^,4);
>> Because I think dynamic arrays does not garantee that all elements are
>> together in a big chunck. 
JH> I think that this *is* guaranteed.

In fact I'm quite sure that it is not garanteed in none of both
arrays, static and dynamic, but it happends always in static as it is
convenient in all terms. In fact I think this code in static arrays is
wrong:

A: array [0..1] of byte;
....
move(a,somewhere,2);

It could or could not work in different architectures.

-- 
Best regards,
 José




More information about the fpc-pascal mailing list