PERSPECTIVAS DE FUTURO
7.2.3. Segmentación en bloques y partición de la deformación
The arguments that the caller of a function specifies on the function call line are called actual arguments. The arguments declared in a definition of a function is called dummy arguments. A maximum of 32 arguments can be stated.
n
Actual Arguments
The arguments that the caller of a function specifies on the function call line are called actual arguments. The following can be used as actual arguments for functions:
• Constants
• Local simple variables
• Local variable array elements • Local variable array
• Tag names
• Generic name simple variables • Generic name array elements • Generic name arrays
When the value of a dummy argument is changed in a function, the value of the actual argu- ment on the caller side is also changed. If an actual argument is a constant, however, an error will be caused during execution when the corresponding dummy argument is changed. The following example shows that the entire array is specified as the actual argument in a function call: integer al[10],a2[3,6] char*16 str integer example( ) integer i1,i2 ...
example(al[*],i1,a2[*], i2,str) !function call ...
As shown in the above example, an asterisk “*” can be attached to the array name when the entire array is specified.
n
Dummy Arguments
The following points need to be taken care of when implementing the declaration statements for dummy arguments.
• To declare a dummy argument of character-string type, specify 0 as the length of string as in “char*0.” With this setting, the character-string type argument is regarded as a string of the same length as the actual argument.
• To declare dummy arguments as a one-dimensional array, state ‘*’ as the number of ele- ments. With this setting, the one-dimensional array argument is regarded as an array having the same size as the actual argument.
• To declare dummy arguments as a two-dimensional array, state ‘*’ as the number of one- dimensional elements while using the same value as the actual argument for the number of two-dimensional elements. In SEBOL, the elements of two-dimensional arrays are ar- ranged in such a way that the two-dimensional elements are updated first. Therefore, subscript calculation for array elements requires the size (number) of the two-dimensional elements.
The following shows an example of using a character string, one-dimensional array and two- dimensional array as arguments:
! calling program integer a1[10],12[3,6] char*16 str integer example() integer i1,i2 ...
example(a1,i1,a2,i2,str) ! function call ...
...
! called function
integer function example (b1,n1,b2,n2,s)
integer b1[*] ! declaration of one-dimensional array dummy argument integer n1
integer b2[*,6] ! declaration of two-dimensional array dummy argument integer n2
char*0 s ! declaration of character-string dummy argument ...
...
n
Actual Argument/Dummy Argument Type Inspection
When a SEBOL program calls a function, whether or not the type of the actual argument agrees with that of the dummy argument is checked. If either of the following two conditions is satisfied, mismatching of types is detected and a run-time error occurs:
• When the actual argument is a local variable and the dummy argument is a function block • When the actual argument is a function block and the dummy argument is a local variable The table below shows how the actual argument and dummy argument correspond with each other when both arguments are local variables:
<4.3 Function Arguments>
4-6
Table 4.3-1 Correspondence Between Local Variable Arguments
Actual argument Declared dummy argument(*1)
Simple One-dimensional array Two-dimensional array
Constant x - -
Simple x - -
Array element x - -
One-dimensional array - x x
Two-dimensional array - x x
*1: x: Operation is performed normally. -: Results in a run-time error.
As shown in the table above, no error occurs at run time if both the actual argument and dum- my argument are either a one-dimensional array or a two-dimensional array. Since the ele- ments of two-dimensional arrays are arranged in such a way that the two-dimensional ele- ments are updated first, they correspond to the elements of one-dimensional arrays (or one- dimensional array type) in this order.
The following example shows what happens when the actual argument is a two-dimensional array and the dummy argument is a one-dimensional array:
! calling program
integer array[2,4] ! actual argument is a two-dimensional array integer example()
...
example(array,8) ! number of elements is 8 ...
! called function
integer function example (arg,n)
integer arg[*] ! dummy argument is declared as a one-dimensional array integer n ! number of elements of the array "arg"
arg[1]=1 ! corresponds to array[1, 1]of the actual argument arg[2]=2 ! corresponds to array[1, 2]of the actual argument arg[3]=3 ! corresponds to array[1, 3]of the actual argument arg[4]=4 ! corresponds to array[1, 4]of the actual argument arg[5]=5 ! corresponds to array[2, 1]of the actual argument arg[6]=6 ! corresponds to array[2, 2]of the actual argument arg[7]=7 ! corresponds to array[2, 3]of the actual argument arg[8]=8 ! corresponds to array[2, 4]of the actual argument
arg[9]=9 ! results in a run-time error because the array subscript
Table 4.3-2 Correspondence When Dummy Argument is a Simple Variable Type Local Variable Actual argu-
ment type
Dummy argument type(*1)
integer long float double char*0
integer x x x x -
long x x x x -
float x x x x -
double x x x x -
char*0 - - - - x
*1: x: Operation is performed normally. -: Results in a run-time error.
The following correspondence table applies when the dummy argument is a local variable of array type. Unlike the case where the dummy argument is a simple variable, the actual varia- ble must also be an array if the dummy argument is an array. If the types of actual argument and dummy argument do not match, executing the function call may result in a run-time error.
Table 4.3-3 Correspondence When Dummy Argument is an Array Type Local Variable Actual argu-
ment type
Dummy argument type(*1)
integer long float double char*0
integer x - - - -
long - x - - -
float - - x - -
double - - - x -
char*0 - - - - x
*1: x: Operation is performed normally. -: Results in a run-time error.
n
Function Type Inspection
In case the types of the function are different between the one declared on the caller side and the other of the function in the definition, the latter is used during execution and it causes no run time error.
<4.3 Function Arguments>