mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:11:49 +08:00
03.9.md
This commit is contained in:
7
eBook/examples/chapter_3/CandGo/Makefile
Normal file
7
eBook/examples/chapter_3/CandGo/Makefile
Normal file
@@ -0,0 +1,7 @@
|
||||
include $(GOROOT)/src/Make.inc
|
||||
|
||||
TARG=rand
|
||||
CGOFILES=\
|
||||
c1.go\
|
||||
|
||||
include $(GOROOT)/src/Make.pkg
|
13
eBook/examples/chapter_3/CandGo/c1.go
Normal file
13
eBook/examples/chapter_3/CandGo/c1.go
Normal file
@@ -0,0 +1,13 @@
|
||||
// c1.go
|
||||
package rand
|
||||
|
||||
// #include <stdlib.h>
|
||||
import "C"
|
||||
|
||||
func Random() int {
|
||||
return int(C.random())
|
||||
}
|
||||
|
||||
func Seed(i int) {
|
||||
C.srandom(C.uint(i))
|
||||
}
|
13
eBook/examples/chapter_3/CandGo/c2.go
Normal file
13
eBook/examples/chapter_3/CandGo/c2.go
Normal file
@@ -0,0 +1,13 @@
|
||||
// c2.go
|
||||
package print
|
||||
|
||||
// #include <stdio.h>
|
||||
// #include <stdlib.h>
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
func Print(s string) {
|
||||
cs := C.CString(s)
|
||||
defer C.free(unsafe.Pointer(cs))
|
||||
C.fputs(cs, (*C.FILE)(C.stdout))
|
||||
}
|
Reference in New Issue
Block a user