Beispiel #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))
}
Beispiel #2
0
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))
}
Beispiel #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))
}
Beispiel #4
0
func C() {
	s := C.CString("Hello from C!\n")
	defer C.free(unsafe.Pointer(s))
	C.print(s)
}
Beispiel #5
0
func main() {
	s := "Hello Cgo"
	cs := C.CString(s)
	C.print(cs)
	C.free(unsafe.Pointer(cs))
}
Beispiel #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))
}
Beispiel #7
0
Datei: 1.go Projekt: Garfiled/Rep
func main() {
	//	s := "Hello Cgo"
	//	cs := C.CString(s)
	C.print()
}