omron — Subroutines

Subroutines Argument Mapping When the main program reaches the CALL instruction shown at the top of the figure, the subroutine a_routine is called and the argument list is passed as shown. See the description of the CALL instruction in the eV+ Language Reference Guide for additional details on passing arrays. Argument Passing by Value or Reference An important principle to grasp in using subroutine calls is the way that the passed variables are affected. Variables can be changed by a subroutine, and the changed value can be passed back to the calling program.

If a calling program passes a variable to a subroutine, and the subroutine can change the variable and pass the changed variable back to the calling program, the variable is said to be passed by reference. If a calling program passes a variable to a subroutine but the subroutine cannot pass the variable back in an altered form, the variable is said to be passed by value. Variables you want changed by a subroutine should be passed by reference. In the previous figure, all the variables passed in the CALL statement are being passed by reference. Changes made by the subroutine are reflected in the state of the variables in the calling eV+Language User's Guide, v2.x, 18318-000 Rev A Page 29