6.3 What can be passed by reference?

What can we use to specify a byref parameter? Because a byref parameter is an alias of a column, it makes sense that only objects that represent columns (like variables and byval parameters) can be used to specify a byref parameter.

Let us consider the following example:


Listing 12: What can be passed by reference?
1define sub reset 
2  byref x 
3  x
4end define sub 
5define sub main 
6  local i 
7  invoke reset ix 
8  invoke reset 20×(i+ 2)x 
9end define sub 
10invoke main

This produces the following trace.








A
B CD E F







1
line#







2 10retline#i







3
post ?







4 7 retline#x







5
8
aka col C






“i” is a normal argument to parameter “x”. “i” is local variable name that specifies column D. As a result, it makes sense that parameter “x” becomes an alias of column D.







6 3
0







7 4 retline#x







8 8 expr retline# x






Things get a little interesting here. The expression 20 × (i + 2) x does not specify a column. Instead, the expression specifies a value that can only be determined when line 8 executes. In theory, the value of an expression does not have a column, and therefore it cannot be an argument to a byref parameter. However, most programming languages creates a column so that the expression can be passed as an argument to a byref parameter. Note that column D does not have a name that the pseudocode in subroutine main can refer to (it is anonymous).







9
40
9
aka col D






In this case, column D is allocated to store the result of the expression 20 × (i + 2). This column is allocated on-the-fly as the invoke statement executes. As a result, parameter “x” can now be an alias to column D.







10 3
0






When line 3 executes, whatever column parameter “x” refers to is reset to zero. This time, it is column D. This does not mean that 20 × (i + 2) = 0. It simply overwrites the column that was used to store the value of the expression to zero.







11 4 expr retline# x






When we return from “reset”, all three columns are deallocated, including the one that was allocated to store the result of 20×(i+2). This means that column D, now reset to zero, is never accessible to subroutine “main”.







12 9retline#i







13
post