No we should not support enum types derived from strings

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed May 12 12:31:35 UTC 2021


On Wednesday, May 12, 2021 5:52:28 AM MDT Andrei Alexandrescu via Digitalmars-
d wrote:
> On 5/11/21 10:36 PM, Meta wrote:
> > Last I checked, strings are reference types, in the same way that Java
> > objects are reference types.
>
> Just by means of clarification, that's not true because the length is
> stored with the pointer. This occasionally trips folks starting with D.

To be more precise, a dynamic array in D is essentially

struct Array(T)
{
    size_t length;
    T* ptr;
}

So, the length is stored directly in the struct, and the data is referenced
via the pointer stored in the struct. As such, we often refer to a D dynamic
array as a pseudo-reference type. Either way, while the way it's put
together has some very useful properties (like making it so that multiple
dynamic arrays can be slices of the same data), there's no question that it
can be confusing at first. And of course, that extends to strings, since D
strings are dynamic arrays.

- Jonathan M Davis





More information about the Digitalmars-d mailing list