CGO使用

参考文章:

http://golang.org/cmd/cgo is the primary cgo documentation

There is also a good introduction article at http://golang.org/doc/articles/c_go_cgo.html.

example:https://github.com/golang/go/wiki/cgo

数据类型转换

1.C -> Go:


int(C.int )

// C string to Go string

func C.GoString(*C.char) string

// C string, length to Go string

func C.GoStringN(*C.char, C.int) string

// C pointer, length to Go []byte

func C.GoBytes(unsafe.Pointer, C.int) []byte

2.Go -> C:


C.char

C.schar (signed char)

C.uchar (unsigned char)

C.short

C.ushort (unsigned short)

C.int

C.uint (unsigned int)

C.long

C.ulong (unsigned long)

C.longlong (long long)

C.ulonglong (unsigned long long)

C.float

C.double.

unsafe.Pointer (void*)

// Go string to C string

func C.CString(string) *C.char

var val []byte

(*C.char)(unsafe.Pointer(&val[0]))

你可能感兴趣的:(CGO使用)