Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexible array of array allocation syntax #18933

Open
dlangBugzillaToGithub opened this issue Jan 22, 2015 · 3 comments
Open

More flexible array of array allocation syntax #18933

dlangBugzillaToGithub opened this issue Jan 22, 2015 · 3 comments

Comments

@dlangBugzillaToGithub
Copy link

bearophile_hugs reported this on 2015-01-22T09:50:46Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=14026

CC List

  • Temtaime

Description

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;
}
@dlangBugzillaToGithub
Copy link
Author

temtaime commented on 2015-01-22T17:43:24Z

Why not int[][3] = new int[n][3]; ?
I think it's better.

@dlangBugzillaToGithub
Copy link
Author

bearophile_hugs commented on 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][]

@dlangBugzillaToGithub
Copy link
Author

temtaime commented on 2015-01-22T19:07:41Z

It's too strange in fact because for one dimension it works:

int n;
auto arr = new int[n];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant