[Issue 20546] Сast nested array from static to dynamic.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 30 19:34:12 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20546
moonlightsentinel at disroot.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |moonlightsentinel at disroot.o
| |rg
Resolution|--- |INVALID
--- Comment #1 from moonlightsentinel at 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.
--
More information about the Digitalmars-d-bugs
mailing list