How does array assignment for different sized types work?

estew estewh at gmail.com
Wed Jan 30 20:48:00 PST 2013


void main() {
      float[3] v1 = [1.0, 2.0, 3.0];    // No error
      float[3] v = [1.0, 2.0, 3.0].dup; // Fails at runtime with
error message
}


Why does the array assignment work when "dup" is not used. My
understanding is that arrays, like classes, are references.

So I declare v1 as a float[3] point it at a double[3] literal. Is
v1 now a double[3] or a float[3]? Is there an implicit cast from
double[3] to float[3]?

The dup, gives a compile time error and if cast to float[] it
gives a runtime error. This is all good, I just don't quite
understand how the ref assignment is working...


Thanks,
Stewart


More information about the Digitalmars-d-learn mailing list