Checking if a string is null

Bruno Medeiros brunodomedeiros+spam at com.gmail
Wed Jul 25 07:09:38 PDT 2007


Regan Heath wrote:
>>> So, "" is < and == null!?
>>> and <=,== but not >=!?
>>>
>>
>> You didn't update all writefln's :)
> 
> <hangs head in shame> What can I say, I'm having a bad morning.
> 
>> Anyway, it feels like an undefined area in the language. Do the specs
>> say anything about how exactly arrays/strings/delegates should compare
>> to null? It seems to be more than comparing the pointer part of the
>> structs.
> 
> Not that I can find.  The array page does say:
> 
> "Strings can be copied, compared, concatenated, and appended:"
> ...
> "with the obvious semantics."
> 
> but not much more on the topic.  Under "Array Initialization" we see:
> 
>     * Pointers are initialized to null.
>     ..
>     * Dynamic arrays are initialized to having 0 elements.
>     ..
> 
> Which does not state that an array will be initialised to "null" but 
> rather to something with 0 elements.
> 

It's in
http://www.digitalmars.com/d/expression.html#IdentityExpression
"For static and dynamic arrays, identity is defined as referring to the 
same array elements"

But in current D empty arrays can have a null identity (even if they 
don't allway have), so you can't use 'is' to try do distinguish null 
arrays from empty arrays. Thus effectively they are semantically the 
same in current D.


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



More information about the Digitalmars-d mailing list