range violation

bearophile bearophileHUGS at lycos.com
Mon Feb 28 13:19:45 PST 2011


Dr.Smith:

> For example:
> 
> double [string] data;
> double [200][1000] data2;
> 
> for(int i = 0; i < 200; i++) {
>     for(int j = 0; j < 1000; j++) {
> 
>       // fake multi-dim works
>       string str = to!string(i) ~ "," ~ to!string(j);
>       data[str] = someNumber;
> 
>       // real multi-dim does not work
>       data2[i][j] = someNumber;
>     }
> }

You receive the same stack overflow error with this simpler code:

void main() {
    double[200][1000] a;
}

Keep in mind this is a fixed-sized array, so it's allocated on the stack.

On Windows with DMD if you add a switch like this, to increase max stack size, that code works:
-L/STACK:10000000

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list