Is empty array null?
Mikael Lindsten
mikael at lindsten.net
Tue Feb 28 00:30:01 PST 2012
2012/2/28 Pedro Lacerda <pslacerda at gmail.com>
> 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);
>
>
Hi all,
Sorry if this is a stupid question - I'm new to D but I've been keeping an
eye on it for quite a while (and also read the book).
Coming from the Java/C# world, not distinguishing between an empty array
and null feels strange to me. Is this so for strings as well? ...and in
Pedros example, if you assign null to b and then try to access b.length,
don't you get a NullPointerException? What am I missing?
/ Mikael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20120228/da46e935/attachment.html>
More information about the Digitalmars-d-learn
mailing list