mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-11 23:08:34 +08:00
Update 03.9.md
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
// #include <stdio.h>
|
||||
// #include <stdlib.h>
|
||||
import “C”
|
||||
import "C"
|
||||
|
||||
名称 "C" 并不属于标准库的一部分,这只是 cgo 集成的一个特殊名称用于引用 C 的命名空间。在这个命名空间里所包含的 C 类型都可以被使用,例如 C.uint、C.long 等等,还有 libc 中的函数 C.random() 等也可以被调用。
|
||||
|
||||
@@ -26,7 +26,7 @@ Example 3.2 [c1.go](examples/chapter_3/CandGo/c1.go)
|
||||
|
||||
package rand
|
||||
// #include <stdlib.h>
|
||||
import “C”
|
||||
import "C"
|
||||
func Random() int {
|
||||
return int(C.random())
|
||||
}
|
||||
@@ -49,8 +49,8 @@ Example 3.3 [c2.go](examples/chapter_3/CandGo/c2.go)
|
||||
package print
|
||||
// #include <stdio.h>
|
||||
// #include <stdlib.h>
|
||||
import “C”
|
||||
import “unsafe”
|
||||
import "C"
|
||||
import "unsafe"
|
||||
func Print(s string) {
|
||||
cs := C.CString(s)
|
||||
defer C.free(unsafe.Pointer(cs))
|
||||
|
Reference in New Issue
Block a user