栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

*[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]


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/417727.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号