Array operations

Andy Valencia dont at spam.me
Fri May 2 22:19:53 UTC 2025


In the following code, two questions.  First, is there any 
difference between "x[] = y" and "x[] = y[]"?  It appears not.  
Second, in assigning from arrays of differing sizes, Phobos 
causes an illegal instruction, rather than the sort of exception 
I'd have expected.  I'm curious why they stepped away from D's 
exception architecture?

Thanks!
Andy

```d
import std.stdio : writeln;

void main() {
     int[] x = new int[8];
     x[] = 1;
     int[] y = new int[4];
     y[] = 2;
     x[0 .. 4] = y;
     writeln(x);
     x[] = 1;
     x[0 .. 4] = y[];
     writeln(x);
     x[] = y[];
     writeln(x);
}
```



More information about the Digitalmars-d-learn mailing list