Re: [fpc-devel] SizeOf( const typcasted as shortstring)

2018-08-13 Thread Dmitry Boyarintsev
On Mon, Aug 13, 2018 at 5:24 AM Sven Barth via fpc-devel <
fpc-devel@lists.freepascal.org> wrote:

> It's odd that such expression compiles w/o any warnings or notes. (i.e.
>> "ignoring typecasting for constant value expressions")
>>
>
> Support for typecasts in untyped constants is by design and sometimes
> required, e.g. for unsigned 64-Bit values.
>
> Does it mean, that in case of ShortString casting the value of the
constant string should be extended up to 255 (256?) characters?

thanks,
Dmitry
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] SizeOf( const typcasted as shortstring)

2018-08-13 Thread Sven Barth via fpc-devel
Dmitry Boyarintsev  schrieb am Mo., 13. Aug.
2018, 00:12:

> On Sun, Aug 12, 2018 at 5:40 PM Bart  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.
> It would make sense to return 256, if the constant was declared like this:
> const
>x : ShortString = 'abc';
> and fpc does recognize such typed constant as 256 in size.
>
> It's odd that such expression compiles w/o any warnings or notes. (i.e.
> "ignoring typecasting for constant value expressions")
>

Support for typecasts in untyped constants is by design and sometimes
required, e.g. for unsigned 64-Bit values.

Regards,
Sven

>
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] SizeOf( const typcasted as shortstring)

2018-08-12 Thread Martin

On 13/08/2018 02:32, Martin wrote:

On 13/08/2018 00:12, Dmitry Boyarintsev wrote:
On Sun, Aug 12, 2018 at 5:40 PM Bart > 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

copy and paste, this on prints the length of b
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  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] SizeOf( const typcasted as shortstring)

2018-08-12 Thread Martin

On 13/08/2018 00:12, Dmitry Boyarintsev wrote:
On Sun, Aug 12, 2018 at 5:40 PM Bart > 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  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] SizeOf( const typcasted as shortstring)

2018-08-12 Thread Dmitry Boyarintsev
On Sun, Aug 12, 2018 at 5:40 PM Bart  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.
It would make sense to return 256, if the constant was declared like this:
const
   x : ShortString = 'abc';
and fpc does recognize such typed constant as 256 in size.

It's odd that such expression compiles w/o any warnings or notes. (i.e.
"ignoring typecasting for constant value expressions")

thanks,
Dmitry
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel