Checking if a string is null
Derek Parnell
derek at psyc.ward
Wed Jul 25 17:37:25 PDT 2007
On Wed, 25 Jul 2007 15:05:25 +0200, Frits van Bommel wrote:
> Since both the null string and "" have .length == 0, that means they
> compare equal using those methods (having no contents to compare and
> equal length)
>
> This is all perfectly consistent (and even useful) to me...
However,
string x = "";
means that 'x' is not null because it has a pointer and that points a
string with no content. Something that is null has no pointer and therefore
the length component is not significant. But of course, in order to
represent something that really does have the address of zero we should
only consider 'x' to be null when both x.ptr and x.length are both zero. In
every other case it is not null.
--
Derek Parnell
Melbourne, Australia
"Down with mediocrity!"
More information about the Digitalmars-d-learn
mailing list