This was issue https://github.com/golang/go/issues/9401

The short version of it is even though the size of x is zero, x and i are 
not permitted to occupy the same address in memory. This means the address 
of T.x could be beyond the bounds of t, so if x is the final field in the 
struct, it is assumed to be 1 byte wide, and this is rounded up to 8 bytes 
to ensure an array of T's is properly alligned.

On Friday, 4 August 2017 22:21:22 UTC+10, 樊冰心 wrote:
>
> GOARCH="amd64"
> GOBIN=""
> GOEXE=""
> GOHOSTARCH="amd64"
> GOHOSTOS="darwin"
> GOOS="darwin"
>
> package main
>
> import (
> "fmt"
> "unsafe"
> )
>
> type T struct {
> i int
> x struct{}
> }
>
> func main() {
> var t T
> fmt.Println(unsafe.Sizeof(t))
> }
>
> Since size of struct{} is 0, why the result is 16?
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to