weird empty string

2017-05-12 Thread mogu via Digitalmars-d
```d if (null) "1".writeln; if ("") "2".writeln; if ("" == null) "3".writeln; ``` Output: 2 3 How to understand this?

Re: weird empty string

2017-05-12 Thread Stanislav Blinov via Digitalmars-d
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`, `

Re: weird empty string

2017-05-12 Thread mogu via Digitalmars-d
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 ar

Re: weird empty string

2017-05-12 Thread Yuxuan Shui via Digitalmars-d
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 ar

Re: weird empty string

2017-05-12 Thread ag0aep6g via Digitalmars-d
On 05/13/2017 06:20 AM, Yuxuan Shui wrote: So why does "" has non-null pointer while [] has null pointer? Looks inconsistent. String literals are null-terminated, so "" needs to point at a null byte.

Re: weird empty string

2017-05-14 Thread Kagamin via Digitalmars-d
On Saturday, 13 May 2017 at 03:41:29 UTC, mogu wrote: Thanks very much. This is a little bit confusing. There was a lot of discussion about it: https://issues.dlang.org/show_bug.cgi?id=4733, https://forum.dlang.org/thread/rrrtkfosfnfuybble...@forum.dlang.org