问题:主要是想实现对C函数传入void * 指针操作,测试程序如下
![01error.bmp](https://static.studygolang.com/180629/8f283482fdf1a7a9bbff12e50763d8e7.bmp)
错误如下:
error:
./main.go:23: cannot use p1 (type *_Ctype_void) as type unsafe.Pointer in argument to func literal
=======================================================
程序路径 :https://github.com/JGbooks/golong-/blob/master/01_Cgo-void-unsafe.pointer
怎么解决?初次使用git ,望见谅。
<a href="/user/wwcd" title="@wwcd">@wwcd</a> 明白了,多谢你的回复,我对手册没理解到位,仅仅认为是解释unsafe.Pointer功能作用。现在问题解决了
```
运行结果如下
[root@localhost 01_Cgo-void-unsafe.pointer]# go run main.go
test ok!
TransArgs runtiune is ok!
main OK
```
谢谢你 👍
#2
更多评论
CGO中C的`void*`在GO中是`unsafe.Pointer`,并不是`*C.void`,所以导致报类型不匹配的错,21行修订为`p1 := unsafe.Pointer(p)`应该就好了。
CGO手册中有如下描述
The C type void* is represented by Go's unsafe.Pointer. T
#1