6.2 Byref parameter passed by reference again

A natural question regarding passing by reference is: what happens when a parameter that is passed by reference is passed again by reference to another subroutine? The following pseudocode illustrates this.


Listing 11: Passing by reference again
1define sub reset 
2  byref x 
3  x
4end define sub 
5define sub relay 
6  by ref i 
7  invoke reset i x 
8end define sub 
9define sub main 
10  local m 
11  invoke relay m i 
12end define sub 
13invoke main

This code yields the following trace.










A B CD E F G

explanation










1line#










2pre










3
13
retline#m

“m” is a local variable.










4 post ?










5
11
retline#i

“m” is passed by reference to parameter “i”.










6
12
aka col C

As a result, “i” is an alias to the column that corresponds to “m”.










7
7
retline#x

“i” is passed by reference again to parameter “x”.










8
8
aka col C

“x” is not an alias of column E, but rather an alias of column C! This means that when a byref parameter is passed by reference, the reference is passed along. “x” is not an alias of an alias (or a reference to a reference). One can also say that both column E (“i” of “relay”) and column G (“x” of “reset”) are aliases of column C at the same time.










9
3
0










10
4
retline# x










11
8
retline#i










12
12
retline#m










13post