One case of array assignments
Marco Leise
Marco.Leise at gmx.de
Wed Mar 13 12:51:22 PDT 2013
Am Wed, 13 Mar 2013 03:45:20 +0100
schrieb "bearophile" <bearophileHUGS at lycos.com>:
> Marco Leise:
>
> > But that's probably only because you didn't say:
> >
> > int[100][3] a2 = [1, 2, 3];
> >
> > :D
>
> I don't understand.
int[1][3] a2 = [1, 2, 3];
should obviously be rewritten
int[1][3] a2 = [[1], [2], [3]];
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.
> > We should keep _some_ syntax for statically initializing an
> > array
> > from a single element. It's a far too common task.
>
> I agree.
>
> What I have suggested asks to write code like [[1], [2], [3]]
> instead of [1, 2, 3].
>
> Bye,
> bearophile
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];
--
Marco
More information about the Digitalmars-d
mailing list