rebindable static array

Simen kjaeraas simen.kjaras at gmail.com
Thu Sep 2 10:34:08 PDT 2010


Michal Minich <michal.minich at gmail.com> wrote:

> from high level point of view, there is difference in const(int)[2] and
> const (int [2]). One would expect that it is possible to rebind b. From
> low level/implementation point - there seems to be no difference because
> a and b are value types - there is not indirection.
>
> Possible resolutions:
>
> 1. a = [1,2]; should pass and it is a bug in current implementation
>
> 2. it is not a bug, then disallow writing const(int)[n] - only full const
> should be possible to use to prevent confusion.
>
> 3. it is not a bug, then update language definition to make static and
> dynamic arrays constnes modifiers act the same way.
>
> My first question is it a bug or not, then what would be good thing to
> do...

It is not a bug. As you say, static arrays are value types, and thus not
rebindable. This precludes your solution #1 and #3. As for solution #2,
it is not viable for genericity reasons - T[n] should work no matter what
T is (in this case const(int)). If you need rebindability, use a
(mutable)pointer to (const)static array.

-- 
Simen


More information about the Digitalmars-d-learn mailing list