IBM AS/400 Frozen Dessert Maker User Manual


 
Passing Prototyped Parameters
*-------------------------------------------------------------
* The procedure returns a value of a 10-digit integer value.
* The 3 parameters are all 5-digit integers passed by value.
*-------------------------------------------------------------
D MyFunc PR 10I 0 EXTPROC('DO_CALC')
D 5I 0 VALUE
D 5I 0 VALUE
D 5I 0 VALUE
....
Figure 63. Prototype for Procedure DO_CALC with VALUE Parameters
P DO_CALC B EXPORT
*-------------------------------------------------------------
* This procedure performs a function on the 3 numeric values
* passed to it as value parameters. It also returns a value.
*-------------------------------------------------------------
D DO_CALC PI 10I 0
D Term1 5I 0 VALUE
D Term2 5I 0 VALUE
D Term3 5I 0 VALUE
D Result S 10I 0
C EVAL Result = Term1 ** 2 * 17
C + Term2 * 7
C + Term3
C RETURN Result * 45 + 23
P E
Figure 64. Procedure Interface Definition for DO_CALC Procedure
Passing by Read-Only Reference
An alternative means of passing a parameter to a prototyped procedure or program
is to pass it by read-only reference. Passing by read-only reference is useful if you
must pass the parameter by reference and you know that the value of the param-
eter will not be changed during the call. For example, many system APIs have
read-only parameters specifying formats, or lengths.
Passing a parameter by read-only reference has the same advantages as passing
by value. In particular, this method allows you to pass literals and expressions. It is
important, however, that you know that the parameter would not be changed during
the call.
When a parameter is passed by read-only reference, the compiler may copy the
parameter to a temporary field and pass the address of the temporary. Some condi-
tions that would cause this are: the passed parameter is an expression or the
passed parameter has a different format.
Note: If the called program or procedure is compiled using a prototype in a lan-
guage that enforces the read-only reference method (either ILE RPG using
prototypes, or C), then the parameter will not be changed. If the called
program or procedure does not use a prototype, then the compiler cannot
ensure that the parameter is not changed. In this case, the person defining
the prototype must be careful when specifying this parameter-passing
method.
Chapter 10. Calling Programs and Procedures 137