Checking if a string is null

Derek Parnell derek at psyc.ward
Wed Jul 25 17:43:36 PDT 2007


On Wed, 25 Jul 2007 14:31:28 +0100, Bruno Medeiros wrote:

> The .ptr of empty arrays may be different than the .ptr of null arrays, 
> but they are conceptually the same, and thus not safely distinguishable.

No they are not! Conceptually they are different things. However, D
sometimes implements them as the same thing.

> Example:
> 	writefln("" is null); // false
> 	writefln("".dup is null); // true
>
> "".ptr is not null, but "".dup.ptr is null. Such duplication is correct, 
> because empty arrays are conceptually the same as null arrays, and 
> trying to use .ptr do distinguish them is unsafe, 
> implementation-depedendent behavior (aka a program error).

But I believe that the implementation here is wrong. "".dup should create
another empty string and not a null string. 

-- 
Derek Parnell
Melbourne, Australia
"Down with mediocrity!"


More information about the Digitalmars-d-learn mailing list