mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 12:32:21 +00:00
29 lines
430 B
Go
29 lines
430 B
Go
// 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)
|
|
}
|