weird empty string

Stanislav Blinov via Digitalmars-d digitalmars-d at puremagic.com
Fri May 12 17:59:14 PDT 2017


On Saturday, 13 May 2017 at 00:36:55 UTC, mogu wrote:
> ```d
> if (null)
>     "1".writeln;
> if ("")
>     "2".writeln;
> if ("" == null)
>     "3".writeln;
> ```
>
> Output:
> 2
> 3
>
> How to understand this?

Boolean conversion on an array works on array's pointer, not it's 
length. So even though `"".length == 0`, `"".ptr != null`, and so 
`cast(bool)"" == true`.


More information about the Digitalmars-d mailing list