On 5/11/17 7:12 PM, deadalnix wrote:
On Thursday, 11 May 2017 at 12:26:11 UTC, Steven Schveighoffer wrote:
if(arr) -> same as if(arr.ptr)

Nope. It is:

if(arr) -> same as if(((cast(size_t) arr.ptr) | arr.length) != 0)

Should we conclude from the fact that absolutely nobody gets it right in
this very forum that nobody will get it right outside ? I'll let you judge.


Yep, you are right. It's checking the length too. Although in practice, almost never do you have a null pointer array with non-zero length.

Just for your amusement, I wrote the test this way :)

Stevens-MacBook-Pro:testd steves$ cat testifarrptr.d
void main()
{
    char[] x = null;
    x = x.ptr[0 .. 1];
    if(x)
    {
        import std.stdio;
        writeln("ok, deadalnix was right");
    }
}
Stevens-MacBook-Pro:testd steves$ dmd -run testifarrptr.d
ok, deadalnix was right


-Steve

Reply via email to