On Tuesday, 21 May 2013 at 22:24:06 UTC, Nick Sabalausky wrote:
On Mon, 06 May 2013 11:14:56 +0200
"Kagamin" <s...@here.lot> wrote:

On Monday, 29 April 2013 at 09:38:10 UTC, David wrote:
> Null blows up your code, "" doesn't.

There's no difference between null and empty string in D.


That's not true:

    assert("" !is null); // Passes

Or did I misunderstand what you meant?

Strings are slices which are a pointer and a length. I think a slice compares equal to null only if the pointer part is null. However, a slice with a null pointer and a length of zero is still a valid empty slice, which is slightly odd behaviour compared to other languages...

An empty string literal initialises the pointer to non-null because string literals are null terminated, so the memory block actually has a length of one, even though the slice has length zero.

Reply via email to