by matthw · 17y ago · 0 comments
Given that it has garbage collection, arrays/slices, and it disallows pointer arithmetic, it seems it would suffice to use references everywhere.
I thought maybe it was for easy interop with C APIs, but it seems it needs a FFI for that anyway.
Perhaps someone can enlighten me about that design decision? I'm sure there's a reason, I just don't immediately see it.
var s string = "";
Now, I don't see it written there that it is on the stack, but I imagine so. From the source code of 6g, in cgen.c[2], line 884, you can see this comment:
/*
* n is on stack, either local variable
* or return value from function call.
* return n's offset from SP.
*/
Sounds to me that local variables and return values are always on the stack, which makes sense to me.[1] http://golang.org/doc/go_tutorial.html#tmp_44
[2] http://code.google.com/p/go/source/browse/src/cmd/6g/cgen.c?...
Although, gotta wonder how these stack-allocated objects interact with closures.
Maybe this wikipedia article has details: http://en.wikipedia.org/wiki/Thunk