This is the original thread and there's no reply from you prior to this one.<br><br><div class="gmail_quote">On Mon, May 14, 2012 at 9:41 PM, Alex Rønne Petersen <span dir="ltr"><<a href="mailto:xtzgzorex@gmail.com" target="_blank">xtzgzorex@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 14-05-2012 19:16, Gor Gyolchanyan wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
At least we could make an empty string a null array of characters for<br>
consistency. How many times did anyone use the feature of string<br>
literals being null-terminated?<br>
<br>
On Mon, May 14, 2012 at 8:56 PM, Jonathan M Davis <<a href="mailto:jmdavisProg@gmx.com" target="_blank">jmdavisProg@gmx.com</a><br></div><div><div class="h5">
<mailto:<a href="mailto:jmdavisProg@gmx.com" target="_blank">jmdavisProg@gmx.com</a>>> wrote:<br>
<br>
    On Monday, May 14, 2012 14:08:17 Gor Gyolchanyan wrote:<br>
     > Hi! I have a small question:<br>
     > Is the test for a null array equivalent to a test for zero-length<br>
    array?<br>
     > This is particularly interesting for strings.<br>
     > For instance, I could return an empty string from a toString-like<br>
    function<br>
     > and the empty string would be printed, but If I returned a null<br>
    string,<br>
     > that would indicate, that there is no string representation and<br>
    it would<br>
     > cause some default string to be printed.<br>
     > So, the question is, if a null array is any different from an<br>
    empty array?<br>
<br>
    A null array is equal to an empty array.<br>
<br>
    assert(null == []);<br>
    assert(null == "");<br>
<br>
    It's when you use is that things change. An array "is null" only if<br>
    it's ptr<br>
    property is null, which is true only for uninitialized arrays and []<br>
    (the<br>
    compiler doesn't bother allocating memory for [], so it's basically<br>
    the same<br>
    as null). However, since "" is a string literal, it _does_ have memory<br>
    allocated to it, so<br>
<br>
    assert([] is null);<br>
    assert("" !is null);<br>
<br>
    So, it all comes down to the ptr property. An array is considered to<br>
    have a<br>
    length of 0 if its length property is 0 (which null arrays do). It's<br>
    only<br>
    considered to be null if its ptr property is null. == uses the length<br>
    property, ignoring the ptr property as long as the lengths are equal<br>
    (and<br>
    checking each of the elements refered to by the ptr property if the<br>
    lengths<br>
    aren't equal), whereas is specifically checks whether the ptr<br>
    properties of the<br>
    two arrays are equal.<br>
<br>
    Personally, I think that conflating null and empty like this is<br>
    atrocious, but<br>
    that's how the language works, and we're stuck with it.<br>
<br>
    - Jonathan M Davis<br>
<br>
<br>
<br>
<br></div></div>
--<br>
Bye,<br>
Gor Gyolchanyan.<br>
</blockquote>
<br>
See my other post in reply to your original thread.<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
- Alex<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>Bye,<br>Gor Gyolchanyan.<br>