[fpc-pascal] Array issue
Guillermo Martínez Jiménez
gmartinez at burdjia.com
Mon Jun 15 11:57:17 CEST 2026
Hi,
tested your code on Debian 13 + fpc 3.2.2 and had the same output than
you.
I've added another test:
~~~
y := x + [234, 567] + [0, 0];
{ prints [0,0,0,0,0,0] }
for i := Low(y) to High(y) do writeln (y[i]);
~~~
Prints [0,0,0,0,0,0] but shouldn't it be [0,0,234,567,0,0]?
Regards,
Guillermo "Ñuño" Martínez.
El Mon, 15 Jun 2026 11:00:41 +0200
Thomas Kurz via fpc-pascal <fpc-pascal at lists.freepascal.org> escribió:
> 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
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list