Checking if a string is null

Manfred Nowak svv1999 at hotmail.com
Mon Jul 30 07:53:48 PDT 2007


Regan Heath wrote

> To steal Manfred's analogy and twist it to my own purposes.

You are clearly allowed to twist anything. But it is not necessary 
and in this case may introduce confusion.

Sending no envelope is like sending a raw `null', which can represent 
anything including the wish to send nothing.

If one expects to get an array, one can implicitely cast the raw 
`null' to a null array "null[]", which is typeless as this code might 
show:

import std.stdio;
class squared{}
class lined{}
void f( squared[] a){ writefln( "squared");}
void f( lined[] b){ writefln( "lined");}

void main()
{
   f( null); // function f called with argument types
             // (void*) matches both:
             // f(lined[]) and f(squared[])
}

But implicitely casting is another thing than indeed getting a null 
array "null[]", i.e. an empty envelope.

Note that one usually isn't interested in the envelope itself after 
it is opened. Therefore there exists one and only one null array 
"null[]", because no content is no content whereever content might be 
missed.

Therefore: if implicit casting would be disallowed the call `f( 
null)' should give the error cannot implicitely cast `null' to "null
[]" and the call `f( null[])' would introduce the same calling 
ambiguity.

Are further elaborations wanted?

-manfred



More information about the Digitalmars-d mailing list