Thoughts on some code breakage with 2.074
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Thu May 11 16:43:56 PDT 2017
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
More information about the Digitalmars-d
mailing list