Re: Array issue
Sven Barth via fpc-pascal <[email protected]> Tue, 16 Jun 2026 14:21:31 +0200
| Newsgroups | gmane.comp.compilers.free-pascal.general |
|---|---|
| Message-ID | <CAFMUeB8Ujc-kRkBZgmjTGqgiYNvCV5VFJ_2hBxxphJtV2uSV8g@mail.gmail.com> |
--===============8620882036041399885== Content-Type: multipart/alternative; boundary="000000000000865e9206545dfc4d" --000000000000865e9206545dfc4d Content-Type: text/plain; charset="UTF-8" Thomas Kurz via fpc-pascal <[email protected]> schrieb am Mo., 15. Juni 2026, 11:08: > 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 > --000000000000865e9206545dfc4d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"auto"><div><div class=3D"gmail_quote gmail_quote_container"><di= v dir=3D"ltr" class=3D"gmail_attr">Thomas Kurz via fpc-pascal <<a href= =3D"mailto:[email protected]">[email protected]= </a>> schrieb am Mo., 15. Juni 2026, 11:08:<br></div><blockquote class= =3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd= ing-left:1ex">Dear all,<br> <br> I'm observing a strange array issue. Please consider this code:<br> <br> ```<br> program ArrayTest;<br> <br> {$MODESWITCH ARRAYOPERATORS}<br> <br> var x, y: packed array of PtrInt; i: Integer;<br> <br> begin<br> =C2=A0 x :=3D [0,0];<br> <br> =C2=A0 y :=3D System.Copy (x, 0, Length(x)-2) + [234, 567] + [0, 0];<br> =C2=A0 // prints [0,0,0,0]<br> =C2=A0 for i :=3D Low(y) to High(y) do writeln (y[i]);<br> <br> =C2=A0 y :=3D System.Copy (x, 0, Length(x)-2);<br> =C2=A0 y :=3D y + [234, 567];<br> =C2=A0 y :=3D y + [0, 0];<br> =C2=A0 // prints [234,567,0,0]<br> =C2=A0 for i :=3D Low(y) to High(y) do writeln (y[i]);<br> end.<br> ```<br> <br> To me, both assignments to `y` are equal in the end. But the first one resu= lts in `y =3D [0,0,0,0]`, while the second one correctly gives me `y =3D [2= 34,567,0,0]`.<br> <br> I'm on Windows 64, trunk 3.3.1 (Free Pascal Compiler version 3.3.1 [202= 6/03/11] for x86_64) and would appreciate if anyone could try to reproduce = this behavior. Or explain it to me :)<br></blockquote></div></div><div dir= =3D"auto"><br></div><div dir=3D"auto">Please report a bug.=C2=A0</div><div = dir=3D"auto"><br></div><div dir=3D"auto">Regards,=C2=A0</div><div dir=3D"au= to">Sven=C2=A0</div><div dir=3D"auto"><div class=3D"gmail_quote gmail_quote= _container"><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bo= rder-left:1px #ccc solid;padding-left:1ex"> </blockquote></div></div></div> --000000000000865e9206545dfc4d-- --===============8620882036041399885== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ fpc-pascal maillist - [email protected] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal --===============8620882036041399885==--