title: Array subscript is not an integer
body: <p>following this previous question <a href="https://stackoverflow.com/questions/4616503/malloc-memory-corruption-in-c">Malloc Memory Corruption in C</a>, now i have another problem. 
  I have the same code. Now I am trying to multiply the values contained in the arrays A * vc
  and store in res. Then A is set to zero and i do a second multiplication with res and vc and i store the values in A. (A and Q are square matrices and mc and vc are N lines two columns matrices or arrays). 
  Here is my code :</p>
  
  <pre><code>    int jacobi_gpu(double A[], double Q[], 
             double tol, long int dim){
    int nrot, p, q, k, tid;
    double c, s;
    double *mc, *vc, *res;
    int i,kc;
    double vc1, vc2;
  
    mc   = (double *)malloc(2 * dim * sizeof(double));
    vc   = (double *)malloc(2 * dim * sizeof(double));
    vc   = (double *)malloc(dim * dim * sizeof(double));
  
    if( mc == NULL || vc == NULL){
      fprintf(stderr, "pb allocation matricre\n");
      exit(1);
    }
  
    nrot = 0;
  
    for(k = 0; k &lt; dim - 1; k++){
  
      eye(mc, dim);
      eye(vc, dim);
  
      for(tid = 0; tid &lt; floor(dim /2); tid++){
        p = (tid + k)%(dim - 1);
        if(tid != 0)
      q = (dim - tid + k - 1)%(dim - 1);
        else
      q = dim - 1;
  
        printf("p = %d | q = %d\n", p, q);
        if(fabs(A[p + q*dim]) &gt; tol){
  
      nrot++;
      symschur2(A, dim, p, q, &amp;c, &amp;s);
  
  
      mc[2*tid] = p;                                               vc[2 * tid] = c;
      mc[2*tid + 1] = q;                                           vc[2*tid + 1] = -s;
      mc[2*tid + 2*(dim - 2*tid) - 2] = p;                         vc[2*tid + 2*(dim - 2*tid)   - 2 ] = s;
      mc[2*tid + 2*(dim - 2*tid) - 1] = q;                         vc[2 * tid + 2*(dim - 2*tid) - 1 ] = c;
  
  
  
      }
      }
  
      for( i = 0; i&lt; dim; i++){
        for(kc=0; kc &lt; dim; kc++){
      if( kc &lt; floor(dim/2)) {
        vc1 = vc[2*kc + i*dim];
        vc2 = vc[2*kc + 2*(dim - 2*kc) - 2];
      }else {
        vc1 = vc[2*kc+1 + i*dim];
        vc2 = vc[2*kc - 2*(dim - 2*kc) - 1];
      }
      res[kc + i*dim] = A[mc[2*kc] + i*dim]*vc1 + A[mc[2*kc + 1] + i*dim]*vc2;
        }
      }
  
      zero(A, dim);
  
      for( i = 0; i&lt; dim; i++){
        for(kc=0; kc &lt; dim; k++){
      if( k &lt; floor(dim/2)){
        vc1 = vc[2*kc + i*dim];
        vc2 = vc[2*kc + 2*(dim - 2*kc) - 2];
      }else {
        vc1 = vc[2*kc+1 + i*dim];
        vc2 = vc[2*kc - 2*(dim - 2*kc) - 1];
      }
      A[kc + i*dim] = res[mc[2*kc] + i*dim]*vc1 + res[mc[2*kc + 1] + i*dim]*vc2;
        }
      }
  
  
      affiche(mc,dim,2,"Matrice creuse");
      affiche(vc,dim,2,"Valeur creuse");
  
    }
  
    free(mc);
    free(vc);
    free(res);
    return nrot;
  }
  </code></pre>
  
  <p>When i try to compile, i have this error :</p>
  
  <pre><code>    jacobi_gpu.c: In function ‘jacobi_gpu’:
  jacobi_gpu.c:103: error: array subscript is not an integer
  jacobi_gpu.c:103: error: array subscript is not an integer
  jacobi_gpu.c:118: error: array subscript is not an integer
  jacobi_gpu.c:118: error: array subscript is not an integer
  make: *** [jacobi_gpu.o] Erreur 1
  </code></pre>
  
  <p>The corresponding lines are where I store the results in res and A :</p>
  
  <pre><code>res[kc + i*dim] = A[mc[2*kc] + i*dim]*vc1 + A[mc[2*kc + 1] + i*dim]*vc2;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>A[kc + i*dim] = res[mc[2*kc] + i*dim]*vc1 + res[mc[2*kc + 1] + i*dim]*vc2;
  </code></pre>
  
  <p>Can someone explain me what is this error and how can i correct it?
  Thanks for your help. ;)</p>