Is enum static?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Aug 20 16:42:29 PDT 2013
On Wednesday, August 21, 2013 01:21:22 Dicebot wrote:
> On Tuesday, 20 August 2013 at 22:48:26 UTC, Jonathan M Davis
>
> wrote:
> > Static arrays are unsafe in many situations, especially if you
> > end up slicing
> > them by accident.
>
> But we don't prohibit slicing static arrays. Does not seem
> consistent approach. If pointer safety would have been really
> important, `scope` definition and implementation would have been
> a priority.
>
> > The semantics of static arrays are also very different, since
> > they're value types.
>
> But slices of static arrays are still slices. What does it change
> in practice?
Slicing a static array is the equivalent of taking the address of a local
variable. It's a bug that it's not considered @system.
http://d.puremagic.com/issues/show_bug.cgi?id=8838
And IMHO, the fact that the language _ever_ implicitly slices static arrays is
a major design flaw. It's the same as if passing a variable of type T to a
function that accept T* implicitly took the address of that variable rather
than giving an error, and I think that most people would agree that that's a
dumb idea. Unfortunately though, I don't expect it to be fixed at this point,
since it would break too much code to do so.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list