Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2026-06

Array issue

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Thomas Kurz

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

Reply by email

Guillermo Martínez Jiménez
to Thomas Kurz

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.

Show quoted text 40 lines
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 - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Marco van de Voort
to Thomas Kurz: I'm observing a strange array issue. Please consider this code: ``` program ArrayTest;…

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

Show quoted text 33 lines
``` 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 - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Sven Barth
to Thomas Kurz: I'm observing a strange array issue. Please consider this code: ``` program ArrayTest;…

Thomas Kurz via fpc-pascal schrieb am
Mo., 15. Juni 2026, 11:08:

Show quoted text 34 lines
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 :)

Please report a bug.

Regards,
Sven

Reply by email