String Theory Questions
WhatMeWorry via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Sep 13 10:09:56 PDT 2014
The name string is aliased to immutable(char)[]
Why was immutable chosen? Why not mutable. Or why not just make
another alias called
strung where it is aliased to mutable(char)[]
Also, since strings are arrays and arrays are structs with a
length and ptr
field, I ran the following code for both an empty string and a
null string.
string emptyStr = "";
writeln("emptyStr.ptr is ", emptyStr.ptr);
writeln("emptyStr.length is ", emptyStr.length);
string nullStr = null;
writeln("nullStr.ptr is ", nullStr.ptr);
writeln("nullStr.length is ", nullStr.length);
and got the following results:
emptyStr.ptr is 42F080
emptyStr.length is 0
nullStr.ptr is null
nullStr.length is 0
I guess I was expecting them to be equivalent. I can understand
why both lengths are zero. But what is emptyStr.ptr doing with
the 42F080 value? I presume this is a address? If so, what does
this address contain and what is it used for?
Or maybe a more succinct question is why not just set
emptyStr.ptr to null and be done with it?
More information about the Digitalmars-d-learn
mailing list