they both have the same size, eg. following structs bar and bar2 both take 
16 bytes memory on a x64 machine.

package main

import (
    "fmt"
    "unsafe"
)

type bar struct {
    A int
    _ bool
}

type bar2 struct {
    A int
    _ [0]byte

}

func main() {
    bar := bar{}
    bar2 := bar2{}
    fmt.Printf("size of bar:%v\n", unsafe.Sizeof(bar))
    fmt.Printf("size of bar2:%v\n", unsafe.Sizeof(bar2))
}



On Thursday, July 6, 2017 at 11:45:30 AM UTC+8, kortschak wrote:
>
> On Wed, 2017-07-05 at 17:26 -0700, rsr via golang-nuts wrote: 
> > type bar struct { 
> >    A int 
> >    _ bool 
> > } 
>
>
> or `type bar struct { A int; _ [0]byte }` to avoid the additional byte 
> use. 
>
>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to