String Theory Questions

AsmMan via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Sep 13 15:41:38 PDT 2014


On Saturday, 13 September 2014 at 17:31:18 UTC, ketmar via 
Digitalmars-d-learn wrote:
> On Sat, 13 Sep 2014 17:09:56 +0000
> WhatMeWorry via Digitalmars-d-learn 
> <digitalmars-d-learn at puremagic.com>
> wrote:
>
>> 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?
> it's used to keep "empty string". ;-)
>
> note that "null string" and "empty string" aren't same things. 
> arrays
> are reference types and compiler magically knows that 
> "null-arrays" are
> just empty arrays (and you can assign 'null' to array to clear 
> it).
>
> but strings are special in one funny way: when compiler sees 
> string
> literal (i.e. quoted string) in source code, it actually 
> generates
> C-like zero-terminated string. this is to ease C interop, so we 
> can
> call C functions like this: `printf("my string!\n");` instead 
> of this:
> `printf("my string!\n".toStringz);`.
>

D string are actullay C-strings?


More information about the Digitalmars-d-learn mailing list