## digitalmars.D - weird empty string

• mogu (12/12) May 12 ```d
• Stanislav Blinov (4/16) May 12 Boolean conversion on an array works on array's pointer, not it's
• mogu (16/34) May 12 ```d
• Kagamin (4/5) May 14 There was a lot of discussion about it:
• Yuxuan Shui (7/25) May 12 However
• ag0aep6g (2/4) May 12 String literals are null-terminated, so "" needs to point at a null byte...
mogu <mogucpp 163.com> writes:
``````d
if (null)
"1".writeln;
if ("")
"2".writeln;
if ("" == null)
"3".writeln;
```

Output:
2
3

How to understand this?
```
May 12
Stanislav Blinov <stanislav.blinov gmail.com> writes:
```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`.
```
May 12
mogu <mogucpp 163.com> writes:
```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`.

```d
string s1 = null;
string s2 = "";
assert(s1 == null);
assert(s1.ptr == null);
assert(s2 == null);
assert(s2.ptr != null);
if (s1)
1.writeln;
if (s2)
2.writeln;
```

Output:
2

Thanks very much. This is a little bit confusing.
```
May 12
Kagamin <spam here.lot> writes:
```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,
```
May 14
Yuxuan Shui <yshuiv7 gmail.com> writes:
```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.
```
May 12
ag0aep6g <anonymous example.com> writes:
```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.
```
May 12