gpt4 book ai didi

Golang 常量 unsafe.Sizeof

转载 作者:数据小太阳 更新时间:2023-10-29 03:03:23 25 4
gpt4 key购买 nike

不明白为什么我可以做

const OK = uint64(0)

const OK = int(unsafe.Sizeof(uint64(0)))

但不是这个?

const NOK = binary.Size(uint64(0))

最佳答案

specification 中有解释.

Package unsafe 是在编译器中实现的。表达式 unsafe.Sizeof(uint64(0)) can be evaluated at compile time .这是一个 constant expression .

无法在编译时评估函数普通函数调用 binary.Size(uint64(0))。它不是 constant expression .

Constant declarations require a constant expression .

关于Golang 常量 unsafe.Sizeof,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49593861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com