C is Brittle D is Plastic

Nick Treleaven nick at geany.org
Fri Apr 3 13:48:50 UTC 2026


On Friday, 3 April 2026 at 12:20:19 UTC, Quirin Schroll wrote:
> The worst part about D’s strings are auto-decoding and that 
> literals include a secret zero past the end without you asking 
> for it.
>
> About the last thing, maybe in the next Edition, we can have 
> `""z` strings that request a secret zero and only add the zero 
> if a non-z string is used to initialize an  `immutable(char)*` 
> or `const(char)*` (or make it an error to omit the `z` in that 
> case). That would allow for some compression to be done by the 
> compiler: If you have strings in your code like `"BC"` and 
> `"ABCD"`, it could just re-use segment. With the secret zero, 
> it can only re-use suffixes.

If we decide to break existing code in an edition, it should not 
cause unwanted silent runtime behaviour change. Especially 
something so prone to buffer overruns!

If you want a literal to not be zero-terminated, presumably you 
could use a static array?
```d
immutable char[2] s = "hi";
```
That will be a nicer workaround with length inference:
https://dlang.org/changelog/pending.html#dmd.sarr-length-infer


More information about the Digitalmars-d mailing list