From c8e239d0cf835d987a721375ac4002209f17eff4 Mon Sep 17 00:00:00 2001 From: chai2010 Date: Wed, 10 Jan 2018 10:43:19 +0800 Subject: [PATCH] =?UTF-8?q?ch2:=20=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E4=BE=8B=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/ch2-xx/return-go-ptr/main.go | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/ch2-xx/return-go-ptr/main.go diff --git a/examples/ch2-xx/return-go-ptr/main.go b/examples/ch2-xx/return-go-ptr/main.go new file mode 100644 index 0000000..15b51df --- /dev/null +++ b/examples/ch2-xx/return-go-ptr/main.go @@ -0,0 +1,28 @@ +// Copyright © 2017 ChaiShushan . +// 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) +}