Array length & allocation question
Bruno Medeiros
brunodomedeirosATgmail at SPAM.com
Tue Jun 13 06:22:33 PDT 2006
Oskar Linde wrote:
>
> Like this:
>
> void foo(char[] arr) {
> if (!arr)
> writefln("Uninitialized array passed");
> else if (arr.length == 0)
> writefln("Zero length array received");
> }
>
> /Oskar
This is not safe to do. Currently in D null arrays and zero-length
arrays are conceptually the same. It just so happens that sometimes the
arr.ptr is null and sometimes not, depending on the previous operations.
The "A 'dup'ed empty string is now a null string." is an example of why
that is not safe. I thought you knew this already? This is nothing new.
BTW, I do find it (at first sight at least) unnatural that a null array
is the same as a zero-length arrays. It doesn't seem conceptually
right/consistent.
--
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d-learn
mailing list