1. Basic type conversion is simple, directly with coercion type conversion can be, as follows:
Go convert to C:var i intci: = C.int (i) C convert to Go:var i c.intgoi: = Int (i)
2. String type conversion is also not very difficult, one thing to note is that you need to make a small change in converting the char array in C to go string, as follows:
Go convert to C:var str stringcstr: = c.cstring (str) C convert to go:/* #include <stdlib.h> #include <stdio.h>char foo[] = " Hellofoo "; char *bar =" HelloBar "; */import" C "import" FMT "Func Main () {FMT. Printf ("%s\n", C.gostring (&c.foo[0])) FMT. Printf ("%s\n", C.gostring (C.bar))}
3. Array type conversions
The following is an example of an int array, as follows:
This article is from the "Linux related" blog, so be sure to keep this source http://diadia.blog.51cto.com/5440926/1737451
Call c----type conversion in Go language