On Fri, Aug 04, 2017 at 02:09:14AM -0700, jianzhang...@gmail.com wrote: > Hey Guys, > > I'm in trouble in the same issue. My code as the following: > > test.go > ```go > name := []string{"gpu0", "gpu1", "gpu2", "gpu3"} > matrix := [3][3]int{{1, 0, 0}, {3, 3, 0}, {3, 3, 2}} > > C.test_settopologyresource(mod, C.CString("node1"), C.int(2), > (**C.char)(unsafe.Pointer(&name[0])), > (**C.int)(unsafe.Pointer(&matrix[0][0]))) > ```
I'm afraid that's not going to work: the elements of the "name" slice are strings, and they can't be coersed to *C.char because a Go string is internally a struct consisting of a pointer and a length. So I think you'd need to make a "clone" data struct -- something like this: cnames := make([]*C.Char, len(names)) for i, name := range names { cnames[i] = C.CString(name) } and then destroy those objects after returning from the C side: for _, p := range cnames { C.free(p) } [...] -- 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.