Fundamentals of Subprograms
•Each subprogram has a single entry point
•The calling program is suspended during
execution of the called subprogram
•Control always returns to the caller when
the called subprogram’s execution terminates
Local Referencing Environments
•Local variables can be stack-dynamic
-
Advantages
•Support
for recursion
•Storage
for locals is shared among some subprograms
–Disadvantages
•Allocation/de-allocation,
initialization time
•Indirect
addressing
•Subprograms
cannot be history sensitive
•Local variables can be static
–Advantages
and disadvantages are the opposite of those for stack-dynamic local variables
Implementing
Parameter-Passing Methods
•In most languages parameter communication
takes place thru the run-time stack
•Pass-by-reference are the simplest to
implement; only an address is placed in the stack
Design
Considerations for Parameter Passing
•Two important considerations
–Efficiency
–One-way
or two-way data transfer
•But the above considerations are in
conflict
–Good
programming suggest limited access to variables, which means one-way whenever
possible
–But
pass-by-reference is more efficient to pass structures of significant size
Tidak ada komentar:
Posting Komentar