Why are static variables addressed directly while locals are addressed indirectly? I cannot see where the indirection comes from for locals!
Asked
Active
Viewed 969 times
0
-
You don't provide enough context to give a good answer to this question. What programming language; what compiler etc. are you talking about? – Don Stewart May 14 '12 at 18:15
1 Answers
1
In languages that allow functions to be used recursively, locals need to be addressed indirectly (via the stack pointer).
C, however, has also static local variables, hence static
and local
are not necessarily mutually exclusive concepts.

Ingo
- 36,037
- 5
- 53
- 100
-
@Ingro I see, so we first compute the address of the local variable and then read data from the computed memory address. Right? – mrk May 15 '12 at 19:55
-
It depends, of course, on the implementation, but a common thing to do is to let a register (the stack pointer) point to the top/bottom of the stack and then every local variable has a known offset from that stack pointer. – Ingo May 15 '12 at 21:16