Passing an Array to a Launched Module or Subroutine

Arguments to a launched module (or subroutine) are passed by value (i.e. the value of the argument is copied, or assigned, to the module's parameter). For this reason, passing arguments to a launched module is very similar to assigning a value to a variable. It should be no surprise, then, that the rules that govern passing arguments to launched modules are identical to those that govern variable assignment: VTS uses automatic index padding to ensure that only an element of a static array is passed to a launched module, while passing dynamic arrays to launched modules is less restricted. The code below illustrates some common examples:

[

  X Module;  

  ADynamicArray;  

  AStaticArray[3];  

]

 

Init [

  If 1 Main;  

  [  

    ADynamicArray = New(3);  

    X(ADynamicArray);

    { ADyanamic (a pointer) is copied to X\Parm; in this  

    case, X can change the elements of ADynamicArray }  

    X(&AStaticArray);

    { The address of AStaticArray (a pointer) is copied  

    to X\Parm; again, X can change the elements of  

    AStaticArray in this case }  

    X(ADynamicArray[2]); { ADynamic[2] is copied to X\Parm }  

    X(AStaticArray); { AStaticArray[0] is copied to X\Parm }  

    X(AStaticArray[1]); { AStaticArray[1] is copied to X\Parm }  

  ]  

]

 

Main [

]

 

<

  X

 

  (

    Parm;  

  )

 

Main [

]

 

>