5.1 Basic byval parameter

This is a simple program that illustrates the most basic aspects of a byval parameter.


Listing 8: Byval parameter basics
1define sub s1 
2  byval x 
3  yx+3 
4end define sub 
5invoke s1 5x






trace
A BC D

explanation







1line#y







2pre ?

Watch the value of “y” and see how and where it gets changed.







3
5
retline#x

Like a local variable, a byval parameter is allocated a column when a subroutine is invoked.







4 post
5

Unlike a local variable, a byval parameter does start with a specific value. In this case, it is determined by the invoke statement on line 5. The notation “5 x” on line 5 uses the expression on the left (5) to specify the parameter on the right (x). Note that “5” in this case is called an “argument”. An argument is what an invoke statement uses to specify a parameter of a subroutine.







5
3
8







6
4
retline# x







7post