Array literals MUST be immutable.
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Feb 19 08:25:02 PST 2010
Steven Schveighoffer wrote:
> On Fri, 19 Feb 2010 10:22:15 -0500, grauzone <none at example.net> wrote:
>> SafeD will take care of it. As the compiler has to support SafeD
>> anyway, the same mechanisms can be used to create warnings or even
>> errors in normal D code.
>
> I'm not sure where Andrei will draw the line for SafeD. SafeD still has
> to be UsefulD ;)
Good point, but safe means safe. It's can't be a hint. Perhaps the
biggest crisis between Walter and me consumed when he mentioned he
wanted to make "safe" just a hint and still disable bounds checking in
release mode, safe or not. He was kind enough to back off, which was
very nice of him - I see no way in which I could accept a compromise on
that particular matter. (By the way, much of the very fruitful
collaboration between us has been caused by our ability to work out good
compromises even though we have sometimes different viewpoints.)
Statically-allocated arrays are not a difficult safety issue. We have
two solutions - (a) have the compiler just disable conversions for
stack-allocated T[N] to T[] in safe mode, (b) have the compiler perform
its own flow analysis and transparently switch to dynamic allocation
when needed, just like in the case of closures.
> But I think slicing a static array makes the compiler lose all knowledge
> that it is a scoped entity.
I thought the same, but then I figured this works:
int[10] a;
int[5] b = a[0 .. 5];
Well it's off-topic, I know.
I agree that the current situation needs addressing.
Andrei
More information about the Digitalmars-d
mailing list