testcgo.go 251 B

1234567891011121314151617
  1. package main
  2. // #include <stdio.h>
  3. // #include <stdlib.h>
  4. /*
  5. void print(char *str) {
  6. printf("%s\n", str);
  7. }
  8. */
  9. import "C"
  10. import "unsafe"
  11. func main() {
  12. s := "hello"
  13. cs := C.CString(s)
  14. defer C.free(unsafe.Pointer(cs))
  15. C.print(cs)
  16. }