[fpc-pascal] Array issue
Thomas Kurz
fpc.2021 at t-net.ruhr
Mon Jun 15 11:00:41 CEST 2026
Dear all,
I'm observing a strange array issue. Please consider this code:
```
program ArrayTest;
{$MODESWITCH ARRAYOPERATORS}
var x, y: packed array of PtrInt; i: Integer;
begin
x := [0,0];
y := System.Copy (x, 0, Length(x)-2) + [234, 567] + [0, 0];
// prints [0,0,0,0]
for i := Low(y) to High(y) do writeln (y[i]);
y := System.Copy (x, 0, Length(x)-2);
y := y + [234, 567];
y := y + [0, 0];
// prints [234,567,0,0]
for i := Low(y) to High(y) do writeln (y[i]);
end.
```
To me, both assignments to `y` are equal in the end. But the first one results in `y = [0,0,0,0]`, while the second one correctly gives me `y = [234,567,0,0]`.
I'm on Windows 64, trunk 3.3.1 (Free Pascal Compiler version 3.3.1 [2026/03/11] for x86_64) and would appreciate if anyone could try to reproduce this behavior. Or explain it to me :)
Kind regards,
Thomas
More information about the fpc-pascal
mailing list