xjdrew,

The Go Playground is (GOOS/GOARCH) nacl/amd64p32 which is a 64 bit 
architecture, where the address space is limited to a 4GB (32 bit) window. 
It has 8 byte (64 bit) data structure alignment.

linux/386 and windows/386 are 32 bit architectures, where the address space 
is 4GB (32 bit). They have 4 byte (32 bit) data structure alignment.

Peter

On Friday, May 19, 2017 at 7:28:54 AM UTC-4, xjdrew wrote:
>
> Hello everyone,
>
>
> Code as below, playground url(https://play.golang.org/p/XSx--6uF0E):
>
> package main
>
>
> import "fmt"
> import "unsafe"
>
>
> type A struct {
>  a uint8
>  b uint64
> }
> func main() {
>  a := &A{}
>  fmt.Println(unsafe.Sizeof(a))
>  fmt.Println(unsafe.Sizeof(*a))
> }
>
>
> When I run the code in go playground, I get what as i expected.
>
>
>
> 4
> 16
>
> Program exited.
>
>
> but when I test the code in my own environment(linux i386 & win32, both), I 
> get a unreasonable result as below:
>
>
> $ go version 
> go version go1.8.1 linux/386 
> $ go run align.go
> 4 
> 12
>
> Then I test a similar code in C, the result is same as go playground.
>
>
> typedef struct _aaa { UINT8 a; UINT64 b; }AAA;
>
> printf("%d",sizeof(int*)); // 4
> printf("%d",sizeof(AAA)); // 16
>
>
> uint64 should aligin in 8 bytes, why it aligns in 4 bytes in 
> go1.8.1.linux-386?
>
> Could anyone tell me how I can get the same result with go playground?
>
>
> Best regards,
>
> drew
>
>

-- 
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