On Sat, Jul 29, 2017 at 3:20 AM, Jan Mercl <0xj...@gmail.com> wrote: > > I would like to ask for confirmation if I understand correctly few items. > Thank in advance for the answer(s). > > Bellow let's consider only correct, valid, race-free "normal" programs that > do not use CGO or directly call assembler routines etc. > > 1. Once 'p := &v' is executed, the program always observes, through *p, the > same value v had before the assignment unless the program mutates p or *p by > itself. > > 2. The value of p per se is not guaranteed to be the same all the times. The > program may observe different values of p without the program mutating p by > itself. > > 3. The well known existing Go compilers, up to and including version 1.9, > may move *p and update p iff *p is located in a goroutine stack. (Not a > specification guarantee, just an implementation detail.) > > Is all of the above correct?
Yes, that sounds correct. With the proviso for case 1 that of course if v is changed directly then *p will be changed. And for case 2 that the only way the program may observe different values of p is by using the unsafe package to convert pt to uintptr, or by using the fmt package to print p, or by calling reflect.ValueOf(p).Pointer(). 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.