Permalink
Browse files

add cgo sample

  • Loading branch information...
1 parent 3384e1a commit d0a35189024bc0654d3650b7a178025e0f2791e0 @kicool committed Apr 10, 2012
Showing with 23 additions and 0 deletions.
  1. +23 −0 cgo/helloc.go
View
@@ -0,0 +1,23 @@
+package main
+
+/*
+#include <stdio.h>
+#include <stdlib.h>
+
+void myprint(char* s) {
+ printf("%s", s);
+}
+*/
+import "C"
+
+import "unsafe"
+
+func Example() {
+ cs := C.CString("Hello from stdio\n")
+ C.myprint(cs)
+ C.free(unsafe.Pointer(cs))
+}
+
+func main() {
+ Example()
+}

0 comments on commit d0a3518

Please sign in to comment.