Question 1-9
Recall from class that FORTRAN uses static variable
allocation, while most other languages (including Ada and Java)
use stack-dynamic variable allocation.
- a. Name and explain an advantage of static variable
allocation over stack-dynamic variable allocation.
b. Name and explain an advantage of stack-dynamic
variable allocation over static allocation.
Solution
- a.
It is marginally more efficient because the computer can use direct
loads instead of indirect loads.
It allows for variables within functions that can remember values
from previous calls to the function.
- b.
It is much more conducive to recursion, because each recursive
call gets its own set of variables.
It is more space-efficient, as space is only allocated for the
functions currently on the call stack.
Back to Review for Quiz 1