<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 13/08/2018 00:12, Dmitry Boyarintsev
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAMpTZrcmmDkywyGGq+3u1SowL=k2XqxOTCGA5JO=Baa7qKRx3w@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<div dir="ltr">
<div class="gmail_quote">
<div dir="ltr">On Sun, Aug 12, 2018 at 5:40 PM Bart <<a
href="mailto:bartjunk64@gmail.com" moz-do-not-send="true">bartjunk64@gmail.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">const<br>
x = ShortString('abc');<br>
begin<br>
writeln(SizeOf(x));<br>
end.<br>
<br>
Delphi (7) prints 256, fpc prints 3.<br>
<br>
Is that a bug or an implementation detail?<br>
</blockquote>
<div> </div>
<div>Implementation detail.</div>
<div>And it seems to be wrong on Delphi size, because for
reason it assigns a type to a (non-typed) constant.</div>
<br>
</div>
</div>
</blockquote>
Interesting.<br>
<br>
Yet the compiler still seems to add some type or at least type
specific behaviour. (That alone is ok)<br>
<br>
But if the first string has the length in a[0], then that constant
has 6 bytes of data. Yet sizeof only reports 5.<br>
So what is the real size of this constant?<br>
<br>
<br>
program Project1; {$H+}<br>
const<br>
a = 'abcde';<br>
b = 'abcde
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';<br>
begin<br>
writeln(SizeOf(a)); // 5<br>
writeln(SizeOf(b)); // 5<br>
writeln(byte(a[0])); // no range check / shortstring has index 0
with length<br>
writeln(byte(b[0])); // range check / not a shortstring<br>
readln;<br>
end.<br>
<br>
<br>
</body>
</html>