From 51eceb15fba38a4439bc155608aef55e8c5de316 Mon Sep 17 00:00:00 2001 From: chai2010 Date: Fri, 27 Jul 2018 05:42:31 +0800 Subject: [PATCH] =?UTF-8?q?ch2-02:=20=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ch2-cgo/ch2-02-basic.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ch2-cgo/ch2-02-basic.md b/ch2-cgo/ch2-02-basic.md index d83e333..6a6f45f 100644 --- a/ch2-cgo/ch2-02-basic.md +++ b/ch2-cgo/ch2-02-basic.md @@ -19,7 +19,6 @@ void printint(int v) { } */ import "C" -import "unsafe" func main() { v := 42 @@ -47,7 +46,7 @@ func (p *CChar) GoString() string { } func PrintCString(cs *C.char) { - print(cs.GoString()) + print(((*CChar)(cs.GoString())) } ``` @@ -56,7 +55,7 @@ func PrintCString(cs *C.char) { ```go package main -// static char* cs = "hello" +// extern char* cs = "hello" import "C" import "./cgo_helper" @@ -121,11 +120,11 @@ package main #cgo linux CFLAGS: -DCGO_OS_LINUX=1 #if defined(CGO_OS_WINDOWS) - static char* os = "windows"; + extern char* os = "windows"; #elif defined(CGO_OS_DARWIN) - static char* os = "darwin"; + extern char* os = "darwin"; #elif defined(CGO_OS_LINUX) - static char* os = "linux"; + extern char* os = "linux"; #else # error(unknown os) #endif