[fpc-pascal] Dynamic arrays, yet another pitfall

patspiper patspiper at gmail.com
Sun Feb 9 19:10:01 CET 2014


On 09/02/14 18:47, Sven Barth wrote:
> On 09.02.2014 16:34, Flávio Etrusco wrote:
>>
>> In other words: dynamic arrays are like AnsiStrings without the
>> copy-on-write semantics. I'd certainly wish Borland copied the COW
>> semantics :-/
>
> Dynamic arrays have full COW semantics.

It seems not:
    SetLength(A,10);
    A[0]:=33;
    B:=A;
    A[0]:=31;
    b[0]:=9;
    WriteLn(a[0], b[0]); // prints 9 and 9 (fpc 2.6.3)

> If Jürgen would have provided a full compilable example we could check 
> whether he has a bug in his own code or there is a bug in the compiler 
> as certainly the result of his first code snipped must be length 10 
> for array "A" and length 20 for array "B". His second example is as 
> expected and as designed.

True on both counts.

Regards,
Stephano



More information about the fpc-pascal mailing list