title: Golang cgo *C.int size differences
body: <p>I am exploring CGO and I have run into a quirk where the size of C.int in the go runtime is 8 bytes but the C int is 4 bytes. I understand that Go ints can be 64 bits or 32 bits depending on architecture, and that C ints are always 32 bits. Is 
  there a standard way for telling go to use 4 bytes for C.int types? I have not been able to find documentation that deals with this.</p>
  
  <p>Because of this the code does not function as anticipated. It basically adds the low side to the high side of the first int. It never references the second int passed.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Actual output:</p>
  
  <pre><code>0xc00001a0b0
  0xc00001a0b8
  0xc00001a0b0
  0xc00001a0b4
  199
  0
  199
  </code></pre>
  
  <p>main.go</p>
  
  <pre><code>package main
  
  /*
  int addNums(int *nums);
  */
  import "C"
  
  import (
      "fmt"
      "unsafe"
  )
  
  func main() {
      var nums [2]C.int
      numsPtr := (*C.int)(unsafe.Pointer(&amp;nums))
      fmt.Println(numsPtr)
      *numsPtr = 199
      numsPtr = (*C.int)(unsafe.Pointer(uintptr(unsafe.Pointer(numsPtr)) + unsafe.Sizeof(numsPtr)))
      fmt.Println(numsPtr)
      *numsPtr = 3
      res, err := C.addNums((*C.int)(unsafe.Pointer(&amp;nums[0])))
      if err != nil {
          fmt.Println(err)
      }
      fmt.Println(res)
  }
  </code></pre>
  
  <p>lib.c</p>
  
  <pre><code>long addNums(int *nums)
  {
    printf("%p\n", &amp;nums[0]);
    printf("%p\n", &amp;nums[1]);
    printf("%d\n", nums[0]);
    printf("%d\n", nums[1]);
    return (nums[0] + nums[1]);
  }
  </code></pre>