I am going through the "A Tour of Go" tutorial and I modified one of the examples a bit to find that the size of bool in Go is 16 bytes?! Am I not using the correct function to calculate this or is it really that the size of bool is 16 bytes?
package main
import "fmt"
import "unsafe"
func do(i interface{}) {
switch v := i.(type) {
case int:
fmt.Printf("Twice %v is %v\n", v, v*2)
case string:
fmt.Printf("%q is %v bytes long\n", v, len(v))
default:
fmt.Printf("I don't know about type %T, but it's length is: %v bytes!\n", v, unsafe.Sizeof(v))
}
}
func main() {
do(21)
do("hello")
do(false)
}
Output:
Twice 21 is 42
"hello" is 5 bytes long
I don't know about type bool, but it's length is: 16 bytes!