On 13/08/2018 00:12, Dmitry Boyarintsev wrote:
On Sun, Aug 12, 2018 at 5:40 PM Bart <[email protected]
<mailto:[email protected]>> wrote:
const
x = ShortString('abc');
begin
writeln(SizeOf(x));
end.
Delphi (7) prints 256, fpc prints 3.
Is that a bug or an implementation detail?
Implementation detail.
And it seems to be wrong on Delphi size, because for reason it assigns
a type to a (non-typed) constant.
Interesting.
Yet the compiler still seems to add some type or at least type specific
behaviour. (That alone is ok)
But if the first string has the length in a[0], then that constant has 6
bytes of data. Yet sizeof only reports 5.
So what is the real size of this constant?
program Project1; {$H+}
const
a = 'abcde';
b = 'abcde
1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890';
begin
writeln(SizeOf(a)); // 5
writeln(SizeOf(b)); // 5
writeln(byte(a[0])); // no range check / shortstring has index 0
with length
writeln(byte(b[0])); // range check / not a shortstring
readln;
end.
_______________________________________________
fpc-devel maillist - [email protected]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel