Is enum static?

Jonathan M Davis jmdavisProg at gmx.com
Tue Aug 20 15:47:50 PDT 2013


On Wednesday, August 21, 2013 00:23:09 John Colvin wrote:
> What I was trying to say was: is there a good reason they are
> always dynamic arrays?
> 
> What would break if they were made static by default but dynamic
> on direct assignment to a dynamic array?

Static arrays are unsafe in many situations, especially if you end up slicing 
them by accident. The semantics of static arrays are also very different, since 
they're value types. Static by default would be a very bad idea IMHO. 
Obviously, static arrays can be desirable, but the programmer needs to be 
careful any time that they're used. Having the compiler avoid allocating a 
dynamic array in any situation where a static one is clearly warranted is 
certainly desirable, as it avoids unnecessary allocations, but that's very 
different from making static the default.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list