Hacker News new | comments | show | ask | jobs | submit login

Yes but stack allocation is completely transparent in all languages except C. Well, almost, maybe all low level languages, the point still stands.

In any non-systems language you don't need to know (and knowing it doesn't help you with anything) this stack sorcery you're talking about.




How is stack allocation less transparent in C than in other languages? I don't understand this idea that the stack has something to do with C.

You can mess with the stack in C, you can also mess with the stack in C#. But you don't have to, and normally you don't. You use it in a completely transparent manner, not caring where the compiler decides to put your data.


> A function that accesses a local variable of a function that has since been popped off the stack

Here is where it's less transparent. In a language like javascript there is no concept of a stack so what's in the quote doesn't make any sense.


In the C language there is no "concept of a stack" either because the stack is not a language-level feature in most languages, it is a mechanic relevant to how your code is compiled / executed. And javascript engines, when executing JS, do use the stack. You can see a stack trace for your code in Chrome...

When it comes to stack allocation, in C this is the compiler's decision and in JS this is the execution engine's decision.

In JS, that quote makes perfect sense, and the answer is: the engine checks what can be safely put on the stack, and the stuff that is closed over is stored on the heap to avoid losing it when the function returns.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: