Stack-Dynamic Storage Binding:
Stack-dynamic variables are bound to storages when execution reaches the codeGo To Static Storage Binding
to which the declaration is attached. (But, data types are statically bound.)
That is, stack-dynamic variables are allocated from the run-time stack.e.g. A Pascal procedure consists of a declaration section and a code section.Recursive subprograms: each call of subprogram has its own local storage.
e.g. FORTRAN 77 and FORTRAN 90 use SAVE list for stack-dynamic list.
e.g. C and C++ assume local variables are static-dynamic.
Advantage: allows recursion; conserves storageDisadvantage:
- Overhead of allocation and deallocation
- Subprograms cannot be history sensitive
- Inefficient references (indirect addressing)
public class Try { public static void main(String [] arg) { Recursion(3); } public static void Recursion(int n) { if(n > 0) { n--; Recursion(n); System.out.printf("%d ", n); } } }
//C++ program#include <iostream.h> void Recursion(int n) { if(n > 0) { n--; Recursion(n); cout<<n<<” “; } }void main() { Recursion(3); }