One case of array assignments

bearophile bearophileHUGS at lycos.com
Wed Mar 13 13:10:13 PDT 2013


Marco Leise:

> but
>
> int[100][3] a2 = [1, 2, 3];
>
> would likely have summoned a controversy about array
> initializers with some people finding it reasonable to
> do this.

This code compiles:

void main() {
     int[100][3] a2 = [1, 2, 3];
}

And gives at run-time:

object.Error: lengths don't match for array copy, 300 = 3


> That creates an inconsistency:
>
> // ok, to initialize array of ten with single literal
> int[10] a1 = 1;
> // not ok, to initialize array of ten with single literal ?
> int[10][3] = [1, 2, 3];

Currently that second line of code doesn't work.

Bye,
bearophile


More information about the Digitalmars-d mailing list