January 30, 2020 [Issue 20546] Сast nested array from static to dynamic. | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20546 moonlightsentinel@disroot.org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |moonlightsentinel@disroot.o | |rg Resolution|--- |INVALID --- Comment #1 from moonlightsentinel@disroot.org --- The cast from int[2][2] to int[][] is invalid - you cannot slice across multiple dimensions. import std.stdio; void main(string[] args) { int[2][2] e = [[1,2],[3,4]]; int[][] c = cast(int[][]) e; writeln(c.length); // 1 writeln(c[0].length); // 8589934593 int[2][] valid = e; // no cast needed writeln(valid); // [[1, 2], [3, 4]] } The length of a static array is only known at compile time while the length of a dynamic array is a runtime value. Hence c's length is set to some garbage from the stack. -- |
Copyright © 1999-2021 by the D Language Foundation