<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Virgo Pärna via fpc-devel <<a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>> schrieb am Fr., 28. Juni 2024, 08:41:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, 21 Jun 2024 20:03:56 +0200, Marco van de Voort via fpc-devel <<a href="mailto:fpc-devel@lists.freepascal.org" target="_blank" rel="noreferrer">fpc-devel@lists.freepascal.org</a>> wrote:<br>
> Probably terminate with a heap out of memory error.<br>
<br>
Also depends of platform...<br>
<br>
program tests;<br>
var<br>
  s, s1, s2: ansistring;<br>
begin<br>
  SetLength(s1, High(int32));<br>
  SetLength(s2, High(int32));<br>
  WriteLn(Length(s1));<br>
  WriteLn(Length(s2));<br>
  s := s1 + s2;<br>
  WriteLn(Length(s));<br>
end.<br>
<br>
Works as 64 bit Windows program:<br>
2147483647<br>
2147483647<br>
4294967294<br>
<br>
But gets "Runtime error 203 at $00404A01" on 32 bit Windows (out of<br>
memory).<br>
<br>
I did not actually know, that string length was 64 bits on 64 bit<br>
platform (at least on Windows), because even uint worked. uint32 version<br>
of same code generated warning at compile time. And uint32 version of<br>
same code results in strings with length 0. Because sizeint is signed.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">The size of the dynamic string types and of dynamic arrays is SizeInt. Thus it matches whatever the size of the underlying architecture is. Thus a UInt32 can lead to problems (and warnings) on 32-bit systems, but not on 64-bit systems. </div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I do not have access to 64 bit Delphi, but Embarcadero RAD Studio Athena<br>
documentation claims, that there ansistring length is limitud to "~2^31<br>
characters". And there is no implication, that 64 bit has different<br>
maximum.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">It doesn't matter what Delphi does here. FPC had 64-bit support before Delphi did and back then we picked the rule set that we thought was best. </div><div dir="auto">Delphi also decided to follow the LP64 vs LLP64 rules regarding the Integer type (it's 32-bit on 64-bit Windows, but 64-bit on 64-bit macOS and Linux) while we decided to keep the size of Integer at 32-bit on 32- and 64-bit systems. </div><div dir="auto">These are differences that will stay this way. </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>