https://play.golang.org/p/jmwRkRSmYjC
package main
import (
"fmt"
"unsafe"
)
type union_t struct {
U32 *uint32
U8_a *[4]byte
}
func newU(u uint32) *union_t {
return &union_t{
&u,
(*[4]byte)(unsafe.Pointer(&u)),
}
}
func main() {
u := newU(0xffffffff)
fmt.Printf("%x, %d %d %d %d\n", *u.U32, (*u.U8_a)[0], (*u.U8_a)[1], (*u.U8_a)[2], (*u.U8_a)[3])
(*u.U8_a)[0] = 0x11
(*u.U8_a)[1] = 0x22
(*u.U8_a)[2] = 0x33
(*u.U8_a)[3] = 0x44
fmt.Printf("%x, %d %d %d %d\n", *u.U32, (*u.U8_a)[0], (*u.U8_a)[1], (*u.U8_a)[2], (*u.U8_a)[3])
}