Hacker News new | ask | show | jobs
by simiones 1749 days ago
Yes, I made a significant error in forgetting what slice variables actually represent. In my example, even fixing the compilation errors (with `_ = append(*ref, 4)` ), v[3] would always be an array index out of bounds error, since v itself always points to just the first 3 elements of the array, regardless of resizing. This is another significant difference between slices and C++ vectors.

A more interesting example showing that resizing can be observed (getting rid of the pointer to the slice, since it's not useful anyway):

https://play.golang.org/p/UJ-t63bKyJJ