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:
parent
3899ac6f45
commit
6b61c309ce
@ -86,7 +86,7 @@ package main
|
||||
void cgoPuts(char* s);
|
||||
|
||||
static void SayHello(const char* s) {
|
||||
cgoPuts(s);
|
||||
cgoPuts((char*)(s));
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
8
examples/ch2-01/hello-01/main.go
Normal file
8
examples/ch2-01/hello-01/main.go
Normal file
@ -0,0 +1,8 @@
|
||||
package main
|
||||
|
||||
//#include <stdio.h>
|
||||
import "C"
|
||||
|
||||
func main() {
|
||||
C.puts(C.CString("Hello, World\n"))
|
||||
}
|
14
examples/ch2-01/hello-02/main.go
Normal file
14
examples/ch2-01/hello-02/main.go
Normal 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"))
|
||||
}
|
5
examples/ch2-01/hello-03/hello.c
Normal file
5
examples/ch2-01/hello-03/hello.c
Normal file
@ -0,0 +1,5 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void SayHello(const char* s) {
|
||||
puts(s);
|
||||
}
|
8
examples/ch2-01/hello-03/main.go
Normal file
8
examples/ch2-01/hello-03/main.go
Normal file
@ -0,0 +1,8 @@
|
||||
package main
|
||||
|
||||
//void SayHello(const char* s);
|
||||
import "C"
|
||||
|
||||
func main() {
|
||||
C.SayHello(C.CString("Hello, World\n"))
|
||||
}
|
22
examples/ch2-01/hello-04/main.go
Normal file
22
examples/ch2-01/hello-04/main.go
Normal 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))
|
||||
}
|
17
examples/ch2-01/hello-05/main.go
Normal file
17
examples/ch2-01/hello-05/main.go
Normal 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))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user