Re: [fpc-devel] Type Compatibility: dynarray <=> Pointer

2018-04-17 Thread Stefan Glienke
That compiles as well because Pointer(0) is converted by the compiler to 
nil.


There is even a dedicated warning for this when used in a const:

http://docwiki.embarcadero.com/RADStudio/Tokyo/en/W1013_Constant_0_converted_to_NIL_(Delphi)


Am 17.04.2018 um 13:24 schrieb Martok:

Am 17.04.2018 um 11:52 schrieb Stefan Glienke:

FWIW this has been changed in Delphi 10.2 and does not compile anymore but 
gives:
E2010 Incompatible types: 'Dynamic array' and 'Pointer'

That is what I would have expected.
Could you please test what the following does in D10.2?

var arr: array of byte;
begin
   arr:= Pointer(0);
end.

What I'd like to know: do they check the "nil" literal, or pointers of value 
nil?




---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus

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


Re: [fpc-devel] Type Compatibility: dynarray <=> Pointer

2018-04-17 Thread Martok
Am 17.04.2018 um 11:52 schrieb Stefan Glienke:
> FWIW this has been changed in Delphi 10.2 and does not compile anymore but 
> gives:
> E2010 Incompatible types: 'Dynamic array' and 'Pointer'
That is what I would have expected.
Could you please test what the following does in D10.2?

var arr: array of byte;
begin
  arr:= Pointer(0);
end.

What I'd like to know: do they check the "nil" literal, or pointers of value 
nil?

-- 
Regards,
Martok


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


Re: [fpc-devel] Type Compatibility: dynarray <=> Pointer

2018-04-17 Thread Stefan Glienke
FWIW this has been changed in Delphi 10.2 and does not compile anymore but 
gives:
E2010 Incompatible types: 'Dynamic array' and 'Pointer'

> On 16 April 2018 at 17:21 Martok  wrote:
>
>
> Hi all,
>
> I have started debugging 0031215, and discovered something slightly unrelated,
> but odd. I hope someone can clear that up.
> While testing, I found out that the following compiles, and becomes a call to
> fpc_dynarray_assign:
>
> var
> arr: array of byte;
> begin
> arr:= Pointer(42);
> end.
>
> This eventually happens because of the conversion case arraydef<=pointerdef in
> defcmp.pas:1151, where a comment says: "nil and voidpointers are compatible 
> with
> dyn. arrays". This comment was there since the very first SVN import.
>
> My question: why *are* voidpointers assignment compatible to dynarrays? It 
> does
> seem to be Delphi compatible, but I couldn't find any mention in either
> documentation that this is possible - only the reserved/constant "nil" is
> compatible, and handled elsewhere.
>
> --
> Regards,
> Martok
>
>
> ___
> 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] Type Compatibility: dynarray <=> Pointer

2018-04-16 Thread Martok
Am 17.04.2018 um 01:51 schrieb Thorsten Engler:
> And the nil assignment variant is pretty much ubiquitous in any code 
> involving dynamic arrays that I'm aware of. 
Yes. I know ;-)

>> only the reserved/constant "nil" is compatible, and handled elsewhere
I asked specifically about assigning arbitrary untyped pointers.


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


Re: [fpc-devel] Type Compatibility: dynarray <=> Pointer

2018-04-16 Thread Thorsten Engler
A zero length dynamic array is represented by a nil pointer instead of a 
pointer to the heap with the information that the length of the array is 0.

arr := nil;

is equivalent to:

SetLength(arr, 0);

And the nil assignment variant is pretty much ubiquitous in any code involving 
dynamic arrays that I'm aware of. 

> -Original Message-
> From: fpc-devel  On Behalf
> Of Martok
> Sent: Tuesday, 17 April 2018 01:21
> To: fpc-devel@lists.freepascal.org
> Subject: [fpc-devel] Type Compatibility: dynarray <=> Pointer
> 
> Hi all,
> 
> I have started debugging 0031215, and discovered something slightly
> unrelated, but odd. I hope someone can clear that up.
> While testing, I found out that the following compiles, and becomes
> a call to
> fpc_dynarray_assign:
> 
> var
>   arr: array of byte;
> begin
>   arr:= Pointer(42);
> end.
> 
> This eventually happens because of the conversion case
> arraydef<=pointerdef in defcmp.pas:1151, where a comment says: "nil
> and voidpointers are compatible with dyn. arrays". This comment was
> there since the very first SVN import.
> 
> My question: why *are* voidpointers assignment compatible to
> dynarrays? It does seem to be Delphi compatible, but I couldn't
> find any mention in either documentation that this is possible -
> only the reserved/constant "nil" is compatible, and handled
> elsewhere.
> 
> --
> Regards,
> Martok
> 
> 
> ___
> 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