Example #1
0
// Hi returns a string from Go (via C's stdio)
func Hi() string {
	cstr := C.CString("hi from go\n")
	defer C.free(unsafe.Pointer(cstr))
	cout := C.cpkg_sprintf(cstr)
	defer C.free(unsafe.Pointer(cout))
	return C.GoString(cout)
}
Example #2
0
// Hello returns a string via C's stdio
func Hello(s string) string {
	if s == "" {
		s = "you"
	}
	cstr := C.CString(fmt.Sprintf("hello %s from go\n", s))
	defer C.free(unsafe.Pointer(cstr))
	cout := C.cpkg_sprintf(cstr)
	defer C.free(unsafe.Pointer(cout))
	return C.GoString(cout)
}