title: Segmentation fault: 11 with large array
body: <p>A simple program compiles fine but gives run-time error: <code>segmentation fault: 11</code></p>
  
  <pre><code>int length=10000;
  int num=100;
  int num1=20;
  int datablocklen=400002; //datablocklen=2*num1*length+2
  
  int main(){
    double arr[num*length];
    double res[num][num];
    for(int i=0;i&lt;num;i++){
      for(int j=0;j&lt;num;j++){
        res[i][j]=0;
      }
    }
    for(int i=0;i&lt;(num*length);i++){
      arr[i]=i;
    }
    int ntile=(int)(num/num1);
    double array_task[datablocklen];
    for(int i=0;i&lt;ntile;i++){
      for(int j=0;j&lt;ntile;j++){
      array_task[datablocklen-2]=i*num1*length;
      array_task[datablocklen-1]=j*num1*length;
        for(int k=0;k&lt;(num1*length);k++){
          array_task[k]=arr[i*num1*length+k];
          array_task[num1*length+k]=arr[j*num1*length];
        }
      }
    }
  return 0;
  }
  </code></pre>
  
  <p><code>gcc -o test -std=c99 test.c</code> to get the executable.  </p>
  
  <p>Strange still, the error does not show up if length is assigned a small value, say, 1000. But when it is larger than 10000, segmentation fault occurs.  </p>
  
  <p>Please <strong>note</strong> that I always keep an eye on the the value of datablocklen to make sure that <code>datablocklen=2*num1*length+2</code>. So if <code>length</code> or <code>num1</code> changes, I will also change variable <code>datablocklen</code>.  </p>
  
  <p>I still have some problem dealing with gdb under mac, OS yosemite. So I have not debugged the program with gdb. But if I comment the inner for loop, the loop indexed by k, the program executes fine. I mean, no error message.  </p>