Is an automatic string variable a dynamic array in the sense of sec. 10.11.2 "Identity Expression" par. 4?

Mathias LANG geod24 at gmail.com
Sat Jul 16 13:03:42 UTC 2022


On Friday, 15 July 2022 at 13:34:03 UTC, kdevel wrote:
>
> the assertion trips although both conditions of the given rule 
> are met.

Another way to express `is` would be to say: their immediate 
value are binary equivalent. For value type it's simple (it also 
means that `float.init is float.init` but not all NaN will be 
equal obviously), but for reference type, it's just comparing 
their pointer (and for arrays, their length).

Note that there is a very subtle difference between `null` and 
`""`, and it matters.
`null` means `.ptr is null && .length == 0` while `""` means 
`.ptr !is null && .length == 0`.

This is crazy, right ? Well no, it's on purpose, because string 
literals have a `\0` past their end, to ensure compatibility with 
C (something we had overwhelming evidence of being a good thing). 
So the "subtle difference" is that `assert("".ptr + 1 == 0);`.


More information about the Digitalmars-d mailing list