[Issue 13407] New: Better error message for static array size overflow
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Aug 31 02:42:54 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13407
Issue ID: 13407
Summary: Better error message for static array size overflow
Product: D
Version: D2
Hardware: x86
OS: Windows
Status: NEW
Keywords: diagnostic
Severity: enhancement
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: bearophile_hugs at eml.cc
This program:
enum N = 9;
long[1 << N][1 << N][N][N] a;
void main() {}
With dmd 2.067alpha gives the error messages:
test.d(2,28): Error: index 9 overflow for static array
test.d(2,28): Error: index 9 overflow for static array
This means that the array is too much large for a statically allocated array,
but I think the meaning error message is not clear enough. So I suggest
something more similar to (a single error message):
test.d(2,28): Error: array 'a' is too much large (512 * 512 * 9 * 9 of 'long')
to be allocated statically.
In such cases you usually replace the static array with a heap-allocated array,
like:
enum N = 9;
long[][][][] a;
void main() {
a = new typeof(a)(1 << N, 1 << N, N, N);
}
But this generates a very large number of dynamic arrays that waste time and
efficiency and stress the garbage collector.
So often a better data structure is an array that has dynamic only one or more
of the last coordinates:
enum N = 9;
long[1 << N][1 << N][][] a;
void main() {
a = new typeof(a)(N, N);
}
Unfortunately I think the error message can't explain this idiom to the user.
--
More information about the Digitalmars-d-bugs
mailing list