weird empty string
Yuxuan Shui via Digitalmars-d
digitalmars-d at puremagic.com
Fri May 12 21:20:25 PDT 2017
On Saturday, 13 May 2017 at 00:59:14 UTC, Stanislav Blinov wrote:
> 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`.
However
if ([])
"1".writeln;
prints nothing.
So why does "" has non-null pointer while [] has null pointer?
Looks inconsistent.
More information about the Digitalmars-d
mailing list