[fpc-devel] Type Compatibility: dynarray <=> Pointer
Thorsten Engler
thorsten.engler at gmx.net
Tue Apr 17 01:51:57 CEST 2018
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 <fpc-devel-bounces at lists.freepascal.org> On Behalf
> Of Martok
> Sent: Tuesday, 17 April 2018 01:21
> To: fpc-devel at 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 at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
More information about the fpc-devel
mailing list