rebindable static array
Michal Minich
michal.minich at gmail.com
Thu Sep 2 09:40:22 PDT 2010
// Original question by Peter Alexander is at http://stackoverflow.com/
questions/3627023/how-do-you-initialise-an-array-of-const-values-in-d2
to summarize consider this code:
const(int)[2] a;
const int [2] b;
const(int)[] c;
const int [] d;
void main () {
a = [1, 2]; // Error: slice a[] is not mutable
// - is it a bug or according specification
b = [1, 2]; // Error: slice b[] is not mutable - this is ok
c = [1, 2]; // can assign - this is ok
// d = [1, 2]; // error - cannot assign - this is ok.
}
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...
More information about the Digitalmars-d-learn
mailing list