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-boun...@lists.freepascal.org> On Behalf > Of Martok > Sent: Tuesday, 17 April 2018 01:21 > To: email@example.com > 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 - firstname.lastname@example.org > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel _______________________________________________ fpc-devel maillist - email@example.com http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel