1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-24 04:22:22 +00:00

ch2-01: 添加例子

This commit is contained in:
chai2010 2018-01-04 17:41:51 +08:00
parent 3899ac6f45
commit 6b61c309ce
7 changed files with 75 additions and 1 deletions

View File

@ -86,7 +86,7 @@ package main
void cgoPuts(char* s);
static void SayHello(const char* s) {
cgoPuts(s);
cgoPuts((char*)(s));
}
*/
import "C"

View File

@ -0,0 +1,8 @@
package main
//#include <stdio.h>
import "C"
func main() {
C.puts(C.CString("Hello, World\n"))
}

View File

@ -0,0 +1,14 @@
package main
/*
#include <stdio.h>
static void SayHello(const char* s) {
puts(s);
}
*/
import "C"
func main() {
C.SayHello(C.CString("Hello, World\n"))
}

View File

@ -0,0 +1,5 @@
#include <stdio.h>
void SayHello(const char* s) {
puts(s);
}

View File

@ -0,0 +1,8 @@
package main
//void SayHello(const char* s);
import "C"
func main() {
C.SayHello(C.CString("Hello, World\n"))
}

View File

@ -0,0 +1,22 @@
package main
/*
#include <stdio.h>
void cgoPuts(char* s);
static void SayHello(const char* s) {
cgoPuts((char*)(s));
}
*/
import "C"
import "fmt"
func main() {
C.SayHello(C.CString("Hello, World\n"))
}
//export cgoPuts
func cgoPuts(s *C.char) {
fmt.Print(C.GoString(s))
}

View File

@ -0,0 +1,17 @@
package main
//void SayHello(char* s);
import "C"
import (
"fmt"
)
func main() {
C.SayHello(C.CString("Hello, World\n"))
}
//export SayHello
func SayHello(s *C.char) {
fmt.Print(C.GoString(s))
}