Is empty array null?

Pedro Lacerda pslacerda at gmail.com
Mon Feb 27 17:45:06 PST 2012


So are a newly allocated array and a null one just the same thing?

    int[] a = [], b = null;
    assert(a == b);
    assert(a.length == b.length);
    assert(a.ptr == a.ptr);

My code made distinction between empty and invalid collections, this mean
that need to track the invalidation on another place?

Pedro Lacerda



2012/2/27 bearophile <bearophileHUGS at lycos.com>

> Jonathan M Davis:
>
> > Arrays treat null kind of funny.
>
> Seen with the knowledge of today, the D confusion between pointers and
> dynamic arrays was a design mistake.
> Recently a bit of this mess was fixed, now this is a syntax error, thanks
> to Don support too:
>
> void main() {
>    auto a = new int[5];
>    *a = 2;
> }
>
> But I'd like this whole situation to be fixed a bit more.
>
> Bye,
> bearophile
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20120227/453c70a2/attachment.html>


More information about the Digitalmars-d-learn mailing list