Checking if a string is null

Bruno Medeiros brunodomedeiros+spam at com.gmail
Thu Jul 26 11:05:20 PDT 2007


Derek Parnell wrote:
> 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.
> 

Check my reply to Regan just above, what I meant to say is that in 
current D they are semantically the same.

>> 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. 
> 

The implementation is not wrong, it is according to Walter's intention, 
as you know. If anything, it is Walter's intention that is wrong. ^^'

-- 
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D


More information about the Digitalmars-d-learn mailing list