array !is null fails
BCS at pathlink.com
Tue Feb 13 09:53:47 PST 2007
Frits van Bommel wrote:
> BCS wrote:
>> Reply to Jarrett,
>>> "BCS" <ao at pathlink.com> wrote in message
>>> news:ce0a334373d48c91d12a1b9c0ec at news.digitalmars.com...
>>>> What good is the (array !is null) if it doesn't tell you when the
>>>> pointer is null?
>>> Well if you want to see if the pointer is null then use "if(array.ptr
>>> is null)". Though I'll agree with you that the discontinuity between
>>> zero-length null pointer arrays and more-than-zero-length null pointer
>>> arrays is a bit odd.
>> What else could be null? I don't see anything else that it could mean
>> other than "is the pointer null".
> 'null', when interpreted as an array, is an _empty_ array with the
> pointer being null.
> This allows it to be a reasonable default initializer for dynamic
> arrays, and means (arr == null) checks whether the array is empty.
Ok, I see that. But aren't the vast majority of comparisons ageist null
asking "Is this readable?" That is the meaning I would expect. Then
again it does bring in a corner case (length checked iff ptr!=null).
It's quite a bother though.
void fn(char c)
//works untill c.ptr == null && c.length != 0
assert(c !is null);
More information about the Digitalmars-d-learn