Re: [go-nuts] gotcha: don't take the address of a for-range loop variable

2019-01-07 Thread Steven Hartland
Worth mentioning you don't need the second _ variable in range statements e.g. use:     for i := range items {    .     } vs:     for i, _ := range items {    .     } On 07/01/2019 02:24, bucha...@gmail.com wrote: https://play.golang.org/p/NnACN5fLPT3 I was taking the address o

Re: [go-nuts] gotcha: don't take the address of a for-range loop variable

2019-01-06 Thread Ian Lance Taylor
On Sun, Jan 6, 2019 at 10:38 PM wrote: > > https://play.golang.org/p/NnACN5fLPT3 > > I was taking the address of the for-loop variable ("&v" in the example above) > and was surprised to find that all my items pointed the same address. I > thought I had found most of the Golang gotchas by now, bu