On Mon, Dec 13, 2021 at 10:43:14PM +0000, forkit via Digitalmars-d-learn wrote: > On Monday, 13 December 2021 at 21:13:25 UTC, H. S. Teoh wrote: > > > > What you should be doing is: > > > > return to!string(str[0 .. len]); > > > > Or just: > > > > return str[0 .. len].idup; [...] > oh.. so many different ways...(to both produce the same bug, and also > to produce the correct output). > > ... it's a little mind boggling ;-) [...]
It's very simple. In C, an array decays to a pure pointer. In D, an array is a pointer + length pair. Given a D array, if you want a pointer to its first element, you use .ptr. Given a D pointer, if you want an array, you slice it with [0 .. length]. That's all there is to it. T -- Almost all proofs have bugs, but almost all theorems are true. -- Paul Pedersen
