Passing arguments between routines
Language Environment-conforming
HLLs use the semantic terms by value and by
reference to indicate how changes in the argument values
for a called routine affect the calling routine:
- By value
- Any changes made to the argument value by the called routine will not alter the original argument passed by the calling routine.
- By reference
- Changes made by the called routine to the argument value can alter the original argument value passed by the calling routine.
Under Language Environment you
can pass arguments directly and indirectly as follows:
- Direct
- The value of the argument is passed directly in the parameter list. You cannot pass an argument by reference (direct).
- Indirect
- A pointer to the argument value is passed in the parameter list.
Table 1 summarizes the semantic terms by value and by reference and the direct and indirect methods for passing arguments. The table shows what is passed to routines.
Term | By value | By reference |
---|---|---|
Direct | The value of the object is passed | Not allowed under Language Environment |
Indirect | A pointer points to the value of an object | A pointer points to the object |
Figure 1 illustrates these argument passing styles. In Figure 1, register 1 (R1) points to the value of an object, or to an argument list containing either a pointer to the value of an object or a pointer to the object.
Figure 1. Argument
passing styles in Language Environment
HLL semantics usually determine when data is passed by value or by reference. Language Environment supports argument passing styles as shown in Table 2.
Language | Default argument |
---|---|
C (including XPLINK). See note 4. | By Value (Direct) |
C++ (including XPLINK). See note 4. | By Value (Direct). See note 1. |
COBOL | By Reference (Indirect) (COBOL BY REFERENCE). See note 2. |
Fortran | By Reference (Indirect) |
PL/I | By Reference (Indirect). See note 3. |
Notes:
- C++ also supports by reference (indirect), if a prototype specifies it with an ampersand (&).
- Other parameter passing styles supported are:
- By value (Indirect) (COBOL BY CONTENT) by Enterprise COBOL for z/OS, COBOL for OS/390 & VM, COBOL for MVS & VM, COBOL/370, and VS COBOL II
- By value (Direct) (COBOL BY VALUE) by Enterprise COBOL for z/OS, COBOL for OS/390 & VM, and COBOL for MVS & VM
- However, when SYSTEM(CICS®)
or SYSTEM(IMS™) is specified, Enterprise PL/I for z/OS and PL/I for MVS & VM main
procedures assume by value (direct) for parameters (OS PL/I main
procedures continue to assume by reference (indirect)). (See PL/I argument passing considerations for a discussion of OPTIONS(BYVALUE).)
PL/I and Fortran also support by value (indirect) (also known as by content), which you can obtain by passing an argument in parentheses, for example, A in CALL X((A), B).
- XPLINK-compiled functions pass arguments by value by default. However it will pass as many arguments in registers as possible in order to reduce the call linkage overhead. See z/OS Language Environment Vendor Interfaces for additional information.