Skip to content

Commit 197c1c8

Browse files
committed
cmd/align64: test program to force compile failure on GOARCH=386
Demonstrates how to get a 64-bit aligned struct on 32-bit arch. Related to golang/go#63131
1 parent 107d2ae commit 197c1c8

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cmd/align64/main.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"sync/atomic"
6+
"unsafe"
7+
)
8+
9+
type S struct {
10+
_ [0]atomic.Uint64
11+
v uint32
12+
}
13+
14+
func main() {
15+
var v S
16+
fmt.Printf("size: %d align: %d", unsafe.Sizeof(v), unsafe.Alignof(v))
17+
var i uintptr
18+
i = uintptr(unsafe.Alignof(v) << 29)
19+
_ = i
20+
}

0 commit comments

Comments
 (0)