Passing parameters

High-level languages pass parameters to an API by value, directly; by value, indirectly; or by reference.

Depending on the high-level language that you use, parameters can be passed in the following ways:

By value, directly

The value of the data object is placed directly into the parameter list.

By value, indirectly

The value of the data object is copied to a temporary location. The address of the copy (a pointer) is placed into the parameter list. By value, indirectly is not done explicitly by the application programmer. It is done by the high-level language at run time.

By reference

A pointer to the data object is placed into the parameter list. Changes made by the called API to the parameter are reflected in the calling application.

When you call an API, the protocol for passing parameters is to typically pass a space pointer that points to the information being passed. (This is also referred to as pass-by-reference.) This is the convention used by default for the control language (CL), RPG, and COBOL compilers. Care must be used in those languages that support pass-by-value (such as ILE C) to ensure that these conventions are followed. Refer to the appropriate language documentation for instructions. The parameter passing convention of pass-by-reference can be used in all programming languages. Some of the UNIX-type APIs require pass-by-value parameter passing. VisualAge® C++ for IBM i also supports pass-by-value parameter passing.

High-level semantics usually determine when data is passed by value and when it is passed by reference. For example, ILE C passes and accepts parameters by value, directly, while for OPM and ILE COBOL and OPM and ILE RPG parameters are usually passed by reference. You must ensure that the calling program or procedure passes parameters in the manner expected by the called API. The OPM or ILE HLL programmer's guides contain more information about passing parameters to different languages.

The ILE languages support the following parameter-passing styles:

  • ILE C passes and accepts parameters by value (directly and indirectly) and by reference.
  • ILE COBOL supports the passing of parameters by value (directly and indirectly) and by reference.
  • ILE RPG supports the passing of parameters by value (directly and indirectly) and by reference.
  • ILE CL supports the passing of parameters by value (directly) and by reference.