Don't understand why I can do
const OK = uint64(0)
const OK = int(unsafe.Sizeof(uint64(0)))
but not this?
const NOK = binary.Size(uint64(0))
Don't understand why I can do
const OK = uint64(0)
const OK = int(unsafe.Sizeof(uint64(0)))
but not this?
const NOK = binary.Size(uint64(0))
It's explained in the specification.
Package unsafe is implemented in the compiler. The expression unsafe.Sizeof(uint64(0))
can be evaluated at compile time. It is a constant expression.
The function plain function call binary.Size(uint64(0))
cannot be evaluated at compile time. It is not constant expression.