I am getting error while doing a shift operation in go with invalid operation: 1 << bucketCntBits (shift count type int, must be unsigned integer)
error on trying to declare a literal in go inside main()
body
Failing literal example: https://play.golang.org/p/EqI-yag5yPp
func main() {
bucketCntBits := 3 // <---- This doesn't work
bucketCnt := 1 << bucketCntBits
fmt.Println("Hello, playground", bucketCnt)
}
When I declare the shift count as a constant, the shift operator works. Working constant example: https://play.golang.org/p/XRLL4FR8ZEl
const (
bucketCntBits = 3 // <---- This works
)
func main() {
bucketCnt := 1 << bucketCntBits
fmt.Println("Hello, playground", bucketCnt)
}
Why does the constant work while the literal doesn't for the shift operator?