HN2new | past | comments | ask | show | jobs | submitlogin

Go is a little more elaborate than that: if a value is initialized as a pointer-to-struct (e.g. foo := &Foo{...}) and it doesn't escape the function, Go will allocate it as if were a value type.


You can stack-allocate in C, with alloca() or by taking the address of a local, and use it like a pointer. So long as you're extremely sure nothing is going to hang onto the pointer beyond the lifetime of that stack frame, it's fine.

Same thing with Go, except that the compiler makes the decision.




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

Search: