Академический Документы
Профессиональный Документы
Культура Документы
1
Parameter passing methods Parameter passing methods (cont.)
• Pass-by-value • Pass-by-value-result
The value of a.p. is used to initialize the corresponding f.p. combination of both previous methods (⇒ in-out-mode)
(⇒ in-mode) • Pass-by-reference
Normally implemented by copying the value The formal parameter becomes an alias for the a.p, which
• Pass-by-result must be a variable (⇒ in-out-mode)
a.p. (which must be a variable) is updated with the value problems
of f.p. (⇒ out-mode) » aliases decreases readability and reliability. The effect
Normally implemented by copying of a subprogram cannot be understood without studying
Problems: the context of the call.
» Parameter collision e.g. sub(x,x) » Two types of aliases: per definition (if the parameter is a
» When is the address of the a.p. computed? (e.g. in non-local variable) and by parameter collision
sub(a[i]) if i is changed in sub)?
» What happens if a.p is an expression?
November
30,
2009
Lennart
Edblom,
Inst.
f.
7
November
30,
2009
Lennart
Edblom,
Inst.
f.
8
datavetenskap
datavetenskap