title: Porting C to Go, having trouble understanding some pointer syntax
body: <p>I'm currently porting some C (as part of a wider R package) to Go. Because the C in question is used as part of an R package, it has to make extensive use of pointers. The R package is <a href="https://github.com/cran/changepoint.np" rel="nofollow noreferrer">changepoint.np</a>.</p>
  
  <p>As somebody who isn't experienced in C, I've managed to understand most of it. However, the following code has me a bit stumped:</p>
  
  <pre><code>double *sumstat; /* matrix in R: nquantile rows, n cols */
  int *n;          /* length of data */
  int *minseglen;  /* minimum segment length */
  int *nquantiles; /* num. quantiles in empirical distribution */
  
  ...[abridged for brevity]...
  
  int j;
  int isum;
  double *sumstatout;
  sumstatout = (double *)calloc(*nquantiles,sizeof(double));
  for (j = *minseglen; j &lt; (2*(*minseglen)); j++) {
      for (isum = 0; isum &lt; *nquantiles; isum++) {
          *(sumstatout+isum) = *(sumstat+isum+(*nquantiles*(j))) - *(sumstat+isum+(*nquantiles*(0)));
      }
  }
  </code></pre>
  
  <p><strong>Specifically, this line</strong> (in the inner for loop):</p>
  
  <pre><code>*(sumstatout+isum) = *(sumstat+isum+(*nquantiles*(j))) - *(sumstat+isum+(*nquantiles*(0)));
  </code></pre>
  
  <p>I've read various pages and Stackoverflow questions/answers about C pointers and arrays, and if I understood them correctly, this line would be translated into Go as:</p>
  
  <pre><code>n := len(data)
  nquantiles := int(4 * math.Log(float64(len(data))))
  
  sumstatout[isum] = sumstat[isum*n + nquantiles*j] - sumstat[isum*n + nquantiles*0]
  </code></pre>
  
  <p>Where n is the number of columns (<code>*n</code> in the C code), and nquantiles is the number of rows (<code>*nquantiles</code> in the C code).</p>
  
  <p>However this produces an error (index out of range, obviously) where the original code does not.</p>
  
  <p>Where am I going wrong?</p>