[fpc-pascal] Array issue

Marco van de Voort fpc at pascalprogramming.org
Mon Jun 15 13:26:21 CEST 2026


Op 15-6-2026 om 11:00 schreef Thomas Kurz via fpc-pascal:
> I'm observing a strange array issue. Please consider this code:

I tested with  todays 3.3.1/win64 and this code:

program ArrayTest;

{$mode delphi}
{$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]
   writeln('first:',length(y));
   for i := Low(y) to High(y) do write (y[i],' ');
   writeln;

   x := [0,0];  // make sure this is what we think it is for second test
   y := System.Copy (x, 0, Length(x)-2);
   y := y + [234, 567];
   y := y + [0, 0];
   // prints [234,567,0,0]
   writeln('second:',length(y));

   for i := Low(y) to High(y) do write (y[i],' ');
writeln;
end.

Output:

first:4
0 0 0 0
second:4
234 567 0 0


>
> ```
> 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