Checking if a string is null
brunodomedeiros+spam at com.gmail
Wed Jul 25 06:31:28 PDT 2007
Frits van Bommel wrote:
> Regan Heath wrote:
>> This all boils down to the empty vs null string debate where some
>> people want to be able to distinguish between them and some see no point.
>> I'm in the 'distinguishable' camp. I can see the merit. At the very
>> least it should be consistent!
> They *are* distinguishable. That's why above code returns different
> results for the 'is' comparison...
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.
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).
Bruno Medeiros - MSc in CS/E student
More information about the Digitalmars-d-learn