How are the function local variables accessed from the stack?

后端 未结 3 493
野性不改
野性不改 2021-02-08 06:49

From http://www.learncpp.com/cpp-tutorial/79-the-stack-and-the-heap/

Here is the sequence of steps that takes place when a function is called:

3条回答
  •  无人及你
    2021-02-08 07:21

    The stack is a metaphoric stack. Remember it is still a RAM, so you can access each address without popping the rest, if you know what you are looking for.

    Since the automatic variable's size is known at compile time - the compiler marks offset for each variable, the offset is determined from where the automatic variables section on stack start [or the stack's head, both are valid and the specific implementation depends might depend on architecture], and it access them by merely: start + offset for each variable's offset.

提交回复
热议问题