D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14026 - More flexible array of array allocation syntax
Summary: More flexible array of array allocation syntax
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-22 09:50 UTC by bearophile_hugs
Modified: 2024-12-13 18:39 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2015-01-22 09:50:46 UTC
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 Temtaime 2015-01-22 17:43:24 UTC
Why not int[][3] = new int[n][3]; ?
I think it's better.
Comment 2 bearophile_hugs 2015-01-22 17:51:27 UTC
(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 Temtaime 2015-01-22 19:07:41 UTC
It's too strange in fact because for one dimension it works:

int n;
auto arr = new int[n];
Comment 4 dlangBugzillaToGithub 2024-12-13 18:39:11 UTC
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