草庐IT

GoString

全部标签

c - 如何将返回的 uint8_u 转换为 ARM 中的 GoString?

我使用cgo从Go调用C函数。该函数的返回类型为uint8_u*。我知道它是一个字符串,需要在Go中打印它。我在myFile.go中有以下内容packagemain//#cgoCFLAGS:-g//#include//#include"cLogic.h"import"C"import("fmt""unsafe")funcmain(){myString:="DUMMY"cMyString:=C.CString(myString)deferC.free(unsafe.Pointer(cMyString))cMyInt:=C.int(10)cResult:=C.MyCFunction(cMy

c - 在 C 中使用 GoString

感谢cgo,我正在尝试在C程序中使用一些Go代码我的Go文件如下所示:packagehelloimport("C")//exportHelloWorldfuncHelloWorld()string{return"HelloWorld"}我的C代码是这样的:#include"_obj/_cgo_export.h"#includeintmain(){GoStringgreeting=HelloWorld();printf("Greetingmessage:%s\n",greeting.p);return0;}但是我得到的输出并不是我所期望的:Greetingmessage:�我猜这是一个编