views:

78

answers:

2

I'm reading Thinking in C++ (vol. 2):

Whenever a function is called, information about that function is pushed onto the runtime stack in an activation record instance (ARI), also called a stack frame. A typical stack frame contains (1) the address of the calling function (so execution can return to it), (2) a pointer to the ARI of the function’s static parent (the scope that lexically contains the called function, so variables global to the function can be accessed), and (3) a pointer to the function that called it (its dynamic parent). The path that logically results from repetitively following the dynamic parent links is the dynamic chain, or call chain

I'm unable to comprehend what the author means as function's static and dynamic parent. Also am not able to differentiate between item 1, 2 or 3. They all seem to be the same. Can someone please explain this passage to me?

+1  A: 

This all sounds very odd to me. Static frame pointers are normally used in languages with lexical scope, such as functional languages, and the pascal family with their nested functions. Globals are bound once either at compile time or runtime, and shouldn't need frame pointers. (1) is valid, but (2) doesn't exist in C++, AFAIK.

I suspect that (3) was meant to refer to the parent frame pointer. Call stacks are usually setup as linked lists so that debuggers and related tools can walk them without requiring deep knowledge of the program.

Marcelo Cantos
+1  A: 

I think this statement is not about C++ but general structure of stack frame. 1) is return address - address of instruction after call in main function. when return is performed it will be poped from stack and execution will go to that point (valid for c++) 2) and 3) are valid for languages that allow nested functions. (Function declared inside function) such functions may have access to parent's variables, so they have link (static link) to parent's stack frame and dynamic link is for this functions to be able call themselves recursively

Andrey