vikkyhacks vikkyhacks - 7 months ago 57
C Question

What is an access link on a stack frame?

I had about access links from wikipedia but I could not get a clear picture of what access links are and how they are different from return address of any function. Can someone explain in brief what an access link is and why its necessary on a call stack ?


You would actually meet such paradigm in Pascal or Java, for example, not in C.

For example, in Java, you could declare:

void func1() {
     int outer = 2;
     int func2() {
        int inner = 3;
        return inner+outer;
     int result = func2();

At the end of func1 execution, the result variable would contain 5 that is a sum of locally defined variables outer and inner.

The access link serves exactly this purpose - to pass the 'pointer' to the actual outer scope into the inner function.

The gcc compiler has Nested Functions extension that is not a part of the C standard as n.m mentioned