*[1 << 30]C.YourType本身不做任何事情,这是一种类型。具体来说,它是指向size
1 <<30,
C.YourType值数组的指针。
您在第三个表达式中所做的是类型转换。这会将转换
unsafe.Pointer为
*[1<< 30]C.YourType。
然后,您将获取转换后的数组值,并将其转换为带有完整切片表达式的切片(切片表达式无需解引用数组值,因此无需在值前加上
*,尽管它是一个指针)。
您可以像这样扩展它:
// unsafe.Pointer to the C arrayunsafePtr := unsafe.Pointer(theCArray)// convert unsafePtr to a pointer of the type *[1 << 30]C.YourTypearrayPtr := (*[1 << 30]C.YourType)(unsafePtr)// slice the array into a Go slice, with the same backing array// as theCArray, making sure to specify the capacity as well as// the length.slice := arrayPtr[0:length:length]


![(* [1 << 30] C.YourType)在CGo中到底做什么? (* [1 << 30] C.YourType)在CGo中到底做什么?](http://www.mshxw.com/aiimages/31/417727.png)
