Re: [go-nuts] issues about struct align

2017-05-21 Thread xjdrew
Here is my c code test: drew@drew-PC MSYS /e/examples/c $ cat align.c #include typedef struct _A { char a; long long b; } A; int main() { printf("%d\n", sizeof(int*)); printf("%d\n", sizeof(A)); } drew@drew-PC MSYS /e/examples/c $ gcc -o align align.c

Re: [go-nuts] issues about struct align

2017-05-21 Thread xjdrew
To Jan & Ohir, thanks for information. Do you run my code example in GO plagground? The pointer size of `a` is 4 bytes, it shows go playground use 32bit go. As my test, the go playground environment is: GOOS: nacl GOARCH: amd64p32 the Machine is amd64, but run 32bit GO. My Machine is

Re: [go-nuts] issues about struct align

2017-05-19 Thread Wojciech S. Czarnecki
Dnia 2017-05-19, o godz. 04:28:53 xjdrew napisaƂ(a): > uint64 should aligin in 8 bytes, why it aligns in 4 bytes in > go1.8.1.linux-386? uint64 member IS 8 bytes wide. It is aligned to the machine word boundary which is 4B (32/8) for 32bit architecture and 8B for 64b one

Re: [go-nuts] issues about struct align

2017-05-19 Thread Jan Mercl
On Fri, May 19, 2017 at 1:29 PM xjdrew wrote: > uint64 should aligin in 8 bytes, why it aligns in 4 bytes in go1.8.1.linux-386? https://en.wikipedia.org/wiki/Data_structure_alignment#Typical_alignment_of_C_structs_on_x86 > Could anyone tell me how I can get the same result

[go-nuts] issues about struct align

2017-05-19 Thread xjdrew
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 := {} fmt.Println(unsafe.Sizeof(a)) fmt.Println(unsafe.Sizeof(*a)) } When I run the code in go playground,