title: How to call a c-function that takes a c-struct that contains pointers
body: <p>From a GO program on a Raspberry PI I'm trying to call a function(Matlab function converted to C function) and the input to the function is a pointer to a struct and the struct contains pointer to a double(data) and a pointer to an int(size) and two int(allocatedSize, numDimensions). I have tried several ways but nothing has worked, when I have passed the compilation it usually throws a panic: runtime error: cgo argument has Go pointer to Go pointer when I run the program. </p>
  
  <p>sumArray.c</p>
  
  <pre><code>/*sumArray.C*/
  /* Include files */
  #include "sumArray.h"
  
  /* Function Definitions */
  double sumArray(const emxArray_real_T *A1)
  {
    double S1;
    int vlen;
    int k;
    vlen = A1-&gt;size[0];
    if (A1-&gt;size[0] == 0) {
      S1 = 0.0;
    } else {
      S1 = A1-&gt;data[0];
      for (k = 2; k &lt;= vlen; k++) {
        S1 += A1-&gt;data[k - 1];
      }
    }
  
    return S1;
  }
  </code></pre>
  
  <p>sumArray.h</p>
  
  <pre><code>#ifndef SUMARRAY_H
  #define SUMARRAY_H
  
  /* Include files */
  #include &lt;stddef.h&gt;
  #include &lt;stdlib.h&gt;
  #include "sumArray_types.h"
  
  /* Function Declarations */
  extern double sumArray(const emxArray_real_T *A1);
  
  #endif
  </code></pre>
  
  <p>sumArray_types.h</p>
  
  <pre><code>#ifndef SUMARRAY_TYPES_H
  #define SUMARRAY_TYPES_H
  
  /* Include files */
  
  /* Type Definitions */
  #ifndef struct_emxArray_real_T
  #define struct_emxArray_real_T
  
  struct emxArray_real_T
  {
    double *data;
    int *size;
    int allocatedSize;
    int numDimensions;
  };
  
  #endif                                 /*struct_emxArray_real_T*/
  
  #ifndef typedef_emxArray_real_T
  #define typedef_emxArray_real_T
  
  typedef struct emxArray_real_T emxArray_real_T;
  
  #endif                                 /*typedef_emxArray_real_T*/
  #endif
  
  /* End of code generation (sumArray_types.h) */
  </code></pre>
  
  <p>main.go</p>
  
  <pre><code>// #cgo CFLAGS: -g -Wall
  // #include &lt;stdlib.h&gt;
  // #include "sumArray.h"
  import "C"
  
  import (
     "fmt"
  )
  func main() {
     a1 := [4]C.Double{1,1,1,1}
     a2 := [1]C.int{4}
     cstruct := C.emxArray_real_T{data: &amp;a1[0], size: &amp;a2[0]}
     cstructArr := [1]C.emxArray_real_T{cstruct}
     y := C.sumArray(&amp;cstructArr[0])
     fmt.Print(float64(y))
  }
  </code></pre>
  
  <p>With this example I get panic: runtime error: cgo argument has Go pointer to Go pointer when I run the program. </p>
  
  <p>I do not how to make it work or if it is possible to make it work. I hope someone can help me or give some direction on how to solve this.</p>