C and C++ parameter passing considerations

C and C++ generally support a single character string as a parameter to a main routine. They parse the string into tokens that are accessed by the argc and argv parameters of the main function.

In addition, there are alternate styles of passing a set of parameters to the main routine, for example: as a single value, a pointer to a value, or a pointer to a list of values. In these cases, the set of parameters is not parsed. It is assumed that the invoker of the application (for example, the operating system) has stored the address of the set of parameters in register 1 before entry into the main routine. Depending on how the parameters are passed, register 1 points on entry to the entities illustrated in Figure 1:

Figure 1. Alternate C/C++ parameter passing styles
In Style 1, Register 1 contains the parameter value. In Style 2, Register 1 contains a pointer to the parameter value. In Style 3, Register 1 contains a pointer to an array of pointers to parameter values.

The first arrangement in Figure 1 can be used only for parameters that are integers.

A C main routine elects to use one of the styles shown in Figure 1 by specifying the PLIST(OS) runtime option in #pragma runopts (see C PLIST and EXECOPS interactions); a C++ routine elects to use one of the styles with the PLIST(OS) compiler option (see C++ PLIST and EXECOPS interactions). The main routine must know which parameter style to expect. When PLIST(OS) is specified, C or C++ makes the parameter list available through a pair of macros; code them in your main routine to determine which parameter list style your routine receives:
__R1 of type void *
__R1 contains the value that is in register 1 on entry into the main routine. It provides access to the parameters when they are passed according to the first two styles shown in Figure 1.
__osplist of type void **
__osplist acts as an array of pointers to parameters. It is derived from __R1 and provides access to the parameters when they are passed according to the third style shown in Figure 1. You must include the header file stdlib.h when using __osplist.

The third style is also supported for certain macros and functions (for example, __pcblist and __csplist for invokers IMS™ and Cross System Product). __osplist is a generalization of the more specialized __pcblist and __csplist macros; it can be used in their place or in cases where they do not apply.

Figure 2 illustrates how these macros can be used to access items in the three alternate parameter arrangements.

Figure 2. Accessing parameters using macros __R1 and __osplist
In Style 1, Register 1 = _R1. 

Suitable casting and dereferencing are required when using these macros, as shown in Figure 3, according to the parameter passing style in use.

Figure 3. Examples of casting and dereferencing
Examples of casting and dereferencing