www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How does array assignment for different sized types work?

reply "estew" <estewh gmail.com> writes:
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
Jan 30 2013
parent "estew" <estewh gmail.com> writes:
Oops, wrong forum. I've moved this to digitalmars.D.learn.
Sorry!
Jan 30 2013