On Tue, Apr 25, 2017 at 5:22 AM, T L <tapir....@gmail.com> wrote: > > package main > > import ( > "unsafe" > ) > > func alignment(p *int64) uintptr { > return unsafe.Alignof(*p) > // compiler doesn't know if *p is a field or a variable. > // so compiler will treat *p as a variable, I think. > } > > type T struct { > x int64 > } > > func main() { > var t T > println( alignment(&t.x) ) // case 1 > println( unsafe.Alignof(*&t.x) ) // case 2 > println( unsafe.Alignof(t.x) ) // case 3 > // Is the case 2 equivalent to case 1 or case 3? > }
Case 2 is equivalent to case 1. AlignOf only has special treatment for a `Selector` (https://golang.org/ref/spec#Selectors) and *&t.x is not a Selector. For the gc toolchain all three cases will be the same value anyhow. It's only gccgo that sometimes has a separate alignment for a field and a value. Ian -- 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.