[Issue 4565] In array literals single values can replace arrays of length 1

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri May 31 10:33:48 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=4565


Shriramana Sharma <samjnaa at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |samjnaa at gmail.com


--- Comment #7 from Shriramana Sharma <samjnaa at gmail.com> 2013-05-31 10:33:43 PDT ---
(In reply to comment #4)
> 
> I think this is not a bad program.
> > int[1][3] a1 = [1, 2, 3];
> is same as:
> 
> int[1][3] a1 = void;
> a1[0][] = 1; // fill all elements by 1
> a1[1][] = 2; // fill all elements by 2
> a1[2][] = 3; // fill all elements by 3
> 
> Then a1 is initialized by [[1], [2], [3]].
> 
> And it is consistent with:
> int[3] sa = 1;  // sa is initialized to [1, 1, 1]

FWIW I agree with bearophile here. In the case of having a single value on the
RHS it is easy (?) to construe how int[3] a = 1 (or even maybe int[3][3] a = 1)
would initialize all the elements, but when you specify an array literal on the
RHS, I think it should have the same shape as the array specified in the type
on the LHS to avoid hard-to-find bugs.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list