But, if I can not change the C client, how to implement it? the C client as the following. As described on the above, I have to change the ` int** _levelmatrix` argument, right? bool test_settopologyresource(bsagomodule* _self, char* _nodename, int _resourceindex, char** _nameunits, int** _levelmatrix) { printf("\n set topology resource-> node:%s, resource index:%d", _nodename , _resourceindex); bool result = settopologyresource(_self->client, _nodename, _resourceindex, _nameunits, _levelmatrix); return result; }
在 2017年8月7日星期一 UTC+8下午10:14:44,Konstantin Khomoutov写道: > > On Mon, Aug 07, 2017 at 06:25:48AM -0700, jianzh...@gmail.com > <javascript:> 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.