Example #1
0
func main() {
	//Go string to C string
	s := "Hello Go string"
	cs := C.CString(s)
	C.print(cs)
	C.free(unsafe.Pointer(cs))

	//C string to Go string
	fmt.Printf("%s\n", C.GoString(C.string))
}
Example #2
0
File: toc.go Project: north91/gonm
func testSlice() {
	msg := "hello world!"
	p := C.calloc((C.size_t)(len(msg)+1), 1)
	println("malloc:", p)

	s := newSlice(p, len(msg)+1)
	copy(s.Data, []byte(msg))

	fmt.Printf("fmt.Printf: %s\n", string(s.Data))
	C.print((*C.char)(p))
}
Example #3
0
func main() {
	fmt.Print("C.print: ")
	cs := C.CString("Hello from cgo\n")
	C.print(cs)
	C.free(unsafe.Pointer(cs))

	fmt.Print("C.factorial: ")
	fmt.Println(C.factorial(5))

	fmt.Print("C.gcd: ")
	fmt.Println(C.gcd(15, 230))

	fmt.Print("C.prime: ")
	C.prime(6)

	fmt.Print("C.fibonacci: ")
	fmt.Println(C.fibonacci(5))
}
Example #4
0
func C() {
	s := C.CString("Hello from C!\n")
	defer C.free(unsafe.Pointer(s))
	C.print(s)
}
Example #5
0
func main() {
	s := "Hello Cgo"
	cs := C.CString(s)
	C.print(cs)
	C.free(unsafe.Pointer(cs))
}
Example #6
0
func main() {
	var s = "hello cgo"
	csl := C.CBytes([]byte(s))
	C.print(csl, C.int(len(s)))
	C.free(unsafe.Pointer(csl))
}
Example #7
0
File: 1.go Project: Garfiled/Rep
func main() {
	//	s := "Hello Cgo"
	//	cs := C.CString(s)
	C.print()
}