Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've been bitten by #5 quite bad. Ranged over N elements in my slice, took the addresses of the values, copied to new slice. Ended up with a slice with N identical values. !?!?!? Took me about 30 mins of staring, printfing and whatnot before I understood what was going on (the loop variable containing the copies is mutable so you end up with pointers to it throughout the whole new slice. And at the end the value of it is the last element in the range. So I saw N*the last element when printing the result).


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: