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

ch2: 增加一个例子

This commit is contained in:
chai2010 2018-01-10 10:43:19 +08:00
parent 54a5c497d1
commit c8e239d0cf

View File

@ -0,0 +1,28 @@
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
package main
// go run x.go
// GODEBUG=cgocheck=0 go run x.go
// panic: runtime error: cgo result has Go pointer
/*
extern int* getGoPtr();
static void Main() {
int* p = getGoPtr();
*p = 42;
}
*/
import "C"
func main() {
C.Main()
}
//export getGoPtr
func getGoPtr() *C.int {
return new(C.int)
}