On Mon, Aug 07, 2017 at 06:25:48AM -0700, jianzhang...@gmail.com wrote:

> Thank you very much for your patience and help. I got it and will try it 
> later. :)

Glad to help!

> > >     golevelmatrix := [][]int{{1}, {3, 3}, {3, 3, 2}} 
> > >    levelmatrix := make([][]C.int, len(golevelmatrix)) 
> > >    for i, _ := range golevelmatrix { 
> > >        levelmatrix[i] = make([]C.int, len(golevelmatrix[i])) 
> > >        for j, _ := range golevelmatrix[i] { 
> > >            levelmatrix[i][j] = C.int(golevelmatrix[i][j]) 
> > >        } 
> > >    } 
[...]

I'd like to reiterate more precisely: your client is expecting a
multi-dimensional array which, in C, would be a contiguous region of
memory.  The Go's [][]C.int is a slice of individual []C.int slices.
Hence when you pass &levelmatrix[0][0] to your C client, it receives the
address of the first element of the first slice, and the only valid
region of memory to access via that pointer is that element and all the
element following it up to (but not including) the length of the first slice.

As soon as the C client attempts to access any memory region other than
that, it may read/write random memory and even invalid memory (at the
addressed which are not allocated/mapped) -- in which case you get
SIGSEGV or the like.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to