Make int[12] convertible to int[]

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sun Jan 11 20:33:25 PST 2015


On Friday, December 19, 2014 09:47:43 Shachar Shemesh via Digitalmars-d wrote:
> On 17/12/14 17:02, Adam D. Ruppe wrote:
> > On Wednesday, 17 December 2014 at 13:13:43 UTC, Shachar Shemesh wrote:
> >> It just seems like extra unneeded superfluous unnecessary redundancy.
> >
> > It is somewhat important because storing a slice to a static array is a
> > big problem:
> >
>
> Any time you pass by reference a reference to a stack allocated
> variable, this problem is there. I don't see how arrays are any different.
>
> What's more, this is precisely why @safe and friends exist (and, if
> memory serves me right, D actually catches and warns about the use case
> you described).

D catches taking the address of a local variable, but it unfortunately does
not currently catch slicing a static array. Regardless, IMHO slicing a
static array should be treated entirely like taking the address of a
variable and not only be considered unsafe but be required to be explicit.
While implicit slicing of static arrays is occasionally nice, it's
definitely a source of nasty bugs, and personally, I think that it was a
mistake to ever have it anywhere in the language.

- Jonathan M Davis



More information about the Digitalmars-d mailing list