why static array can be reassigned with new allocation?
mw
mingwu at gmail.com
Fri Oct 14 18:57:44 UTC 2022
Hi,
``` static_array.d
import std.stdio;
void main() {
int[3] arr;
writeln(arr);
arr = new int[5];
writeln(arr);
}
$ dmd static_array.d
$ ./static_array
[0, 0, 0]
core.exception.RangeError at static_array.d(6): Range violation
----------------
??:? _d_arrayboundsp [0x55e4830afcb5]
??:? _Dmain [0x55e48308f957]
$ ldc2 static_array.d
$ ./static_array
[0, 0, 0]
Illegal instruction (core dumped)
```
Why this code can be compiled and causing runtime error? it
should be caught at compile time!
More information about the Digitalmars-d
mailing list