func main() {
var val int

func f(i int) {
if i--; i == 0 {

this program prints:

[playground (spoilers)]


@diddledan huh, well that's not what I expected. Why does the pointer change?

@diddledan Also weird, the same behavior exists if you set a value
at f(65) the value is the same for the pointer. At f(66) it changes.

Some sort of reallocation? Recursion greater than 64 frames seems to cause it to reallocate memory space.

This actually seems sane since go does not want you to do pointer arithmetic. Though you can use unsafe package.

@diddledan Someone could probably explain the internals more, but I think this is basically what's going on

@diddledan annnnd I missed the twitter link and basically rehashed everything everyone already said!

stack grows and moves, pointers get updated automatically.

This would be bad times if you used unsafe. Everywhere else, perfectly normal and sane.

Sign in to participate in the conversation
Ubuntu Social

This server was setup for the Ubuntu community to use.