This is a creation in Article, where the information may have evolved or changed.
Package main/* #include <STDIO.H&G T #include <string.h> void Fill_array (char *s) { strcpy (S, "Cobbliu"); } void Fill_2d_array (char **arr, int columesize) { strcpy ((char*) (arr+ 0*sizeof (char) *columesize), "Hello"); strcpy ((char*) (arr+1*sizeof (char) *columesize/sizeof ( char*)), "CGO"); } */import "C" import "FMT" imp Ort "unsafe" func main () {var dir [10]byte C.fill_array ((*c.char) (unsafe. Pointer (&dir[0])) FMT. Println (String (dir[:]))//var dirs [4][16]byte Dir S: = make ([][]byte, 4) for I: = 0; I < 4; i++ {Dirs[i] = make ([]byte, +)} c.fill_2d_array ((**c.char) (unsafe. Pointer (&dirs[0][0])), C.int (+)) fmt. Println (dirs)}
It is important to note that slice can not be converted like this: (*c.char) (unsafe. Pointer (&dir)), because slice is actually not a fully-meaningful array in go, it's just a data structure with several heads, see http://blog.golang.org/ Go-slices-usage-and-internals, if the direct &dir, that is equivalent to the DIR this data structure address at the location of the conversion to *c.char, so that the consequences are completely non-period, run-time core off is the result of normal.
Https://groups.google.com/forum/#!topic/golang-nuts/Nb-nfVdAyF0 here is a discussion of multidimensional arrays, see the LAN classmate's reply, for C and go in the multi-dimensional array type of elaboration more clear.
enjoy!