Some array casts
Baz via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 21 06:41:46 PST 2015
On Wednesday, 21 January 2015 at 14:31:15 UTC, bearophile wrote:
> Currently this is accepted:
>
> int[2] m = cast(int[2])[1, 2];
>
> But Kenji suggests that the cast from int[] to int[2][1] should
> not be accepted. Do you know why?
>
> Reference:
> https://issues.dlang.org/show_bug.cgi?id=7514
>
> Bye and thank you,
> bearophile
This is because of the .sizeof property, for example:
void main(string[] args)
{
int[3] m = cast(int[3])[1, 2, 3];
writeln(m.sizeof);
writeln([1, 2, 3].sizeof);
}
outputs 12 / 8
Your previous example is corner case, it's 8/8 in both.
More information about the Digitalmars-d-learn
mailing list