empty arrays and cast(bool): WAT
Regan Heath
regan at netmail.co.nz
Wed Feb 22 08:00:43 PST 2012
On Sun, 19 Feb 2012 06:06:19 -0000, Daniel Murphy
<yebblies at nospamgmail.com> wrote:
> I agree, and I doubt it was intentional.
>
> if (arr) should mean if (arr.length && arr.ptr)
> But since you can only get (arr.length != 0 && arr.ptr == null) when
> doing
> unsafe things with arrays, I think it's entirely reasonable to use
> if (arr) -> if (arr.length)
>
> This is what I expected.
Just to provide a counterpoint, I would have expected if (arr) to check
for null. Coming from a C background I expect the thing inside () to be
compared to 0 and 'the thing' in my mind is the array itself, not any
property of the array length included. Not saying checking for null is a
better or worse idea, just saying that would be my initial impression of
what it would do. I too am unsettled by the conflation of null and empty
- and argued against it on several occasions, but hey, too late now I
suspect.
Regan
More information about the Digitalmars-d
mailing list