Bug 14026 – More flexible array of array allocation syntax

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-01-22T09:50:46Z
Last change time
2024-12-13T18:39:11Z
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: dmd#18933 →

Comments

Comment #0 by bearophile_hugs — 2015-01-22T09:50:46Z
Perhaps we can support this syntax: void main() { uint n = 10; // Run-time value. int[][3] m = new int[][3](n); } That in dmd2.067alpha gives: test5.d(3,30): Error: function expected before (), not new int[][](3u) of type int[][] That means: void main() { uint n = 10; // Run-time value. int[][3] m; foreach (ref a; m) a.length = n; }
Comment #1 by temtaime — 2015-01-22T17:43:24Z
Why not int[][3] = new int[n][3]; ? I think it's better.
Comment #2 by bearophile_hugs — 2015-01-22T17:51:27Z
(In reply to Temtaime from comment #1) > Why not int[][3] = new int[n][3]; ? > I think it's better. That syntax is already taken. n needs to be a compile-time constant, and it creates something different: void main() @safe { enum int n = 2; auto m = new int[n][3]; pragma(msg, typeof(m)); } Output: int[2][]
Comment #3 by temtaime — 2015-01-22T19:07:41Z
It's too strange in fact because for one dimension it works: int n; auto arr = new int[n];
Comment #4 by robert.schadek — 2024-12-13T18:39:11Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18933 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB