相关疑难解决方法(0)

什么(*[1 << 30] C.YourType)完全在CGo中做什么?

Golang wiki中,在"将C数组转换为Go切片"下,有一段代码,演示了如何创建由C数组支持的Go切片.

import "C"
import "unsafe"
...
        var theCArray *C.YourType = C.getTheArray()
        length := C.getTheArrayLength()
        slice := (*[1 << 30]C.YourType)(unsafe.Pointer(theCArray))[:length:length]
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释究竟是什么(*[1 << 30]C.YourType)?它如何unsafe.Pointer变成Go切片?

go cgo

3
推荐指数
1
解决办法
388
查看次数

标签 统计

cgo ×1

go ×1