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:
parent
54a5c497d1
commit
c8e239d0cf
28
examples/ch2-xx/return-go-ptr/main.go
Normal file
28
examples/ch2-xx/return-go-ptr/main.go
Normal 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)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user