Passing arguments in C and C++

Arguments in C and C++ language are copied to the program stack at run time, where they are read by the function. These arguments can either be values in their own right, or they can be pointers to areas of memory that contain the data being passed. Passing a pointer is also known as passing a value by reference.

Other languages, such as COBOL and PL/I, usually pass their arguments by reference, which means that the compiler passes a list of addresses pointing to the arguments to be passed. This is the call interface supported by CICS®. To pass an argument by reference, you prefix the variable name with & , unless it is already a pointer, as in the case when an array is being passed.

As part of the build process, the compiler may convert arguments from one data type to another. For example, an argument of type char may be converted to type short or type long.

When you send values from a C or C++ program to CICS, the translator takes the necessary action to generate code that results in an argument list of the correct format being passed to CICS. The translator does not always have enough information to enable it to do this, but in general, if the argument is a single-character or halfword variable, the translator makes a precall assignment to a variable of the correct data type and passes the address of this temporary variable in the call.

When you receive data from CICS, the translator prefixes the receiving variable name with & , which causes the C or C++ compiler to pass it values by reference rather than by value (with the exception of a character string name, which is left unchanged). Without the addition of & , the compiler would copy the receiving variable and then pass the address of the copy to CICS. Any promotion occurring during this copying could result in data returned by CICS being lost.

Table 1 shows the rules that apply when passing values as arguments in EXEC CICS commands.

Table 1. Rules for passing values as arguments in EXEC CICS commands
Data type Usage Coding the argument
Character literal Data-value (Sender) The user must specify the character literal directly. The translator takes care of any required indirection.
Character variable (char) Data-area (Receiver) The user must specify a pointer to the variable, possibly by prefixing the variable name with &.
Character variable (char) Data-value (Sender) The user must specify the character variable directly. The translator takes care of any required indirection.
Character string literal Name (Sender) The user can either code the string directly as a literal string or use a pointer which points to the first character of the string.
Character string variable Data-area (Receiver) Name (Sender) Whether receiving or sending, the argument should be the name of the character array containing the string—the address of the first element of the array.
Integer variable (short, long, or int) Data-area (Receiver) The user must specify a pointer to the variable, possibly by prefixing the variable name with &.
Integer variable (short, long, or int) Data-value (Sender) The user must specify the name of the variable. The translator looks after any indirection that is required.
Integer constant (short, long, or int) Data-value (Sender) The user must specify the integer constant directly. The translator takes care of any required indirection.
Structure or union Data-area (Sender) Data-area (Receiver) The user must code the address of the start of the structure or union, possibly by prefixing its name with &.
Array (of anything) Data-area (Receiver) Data-value (Sender) The translator does nothing. You must code the address of the first member of the array. This is normally done by coding the name of the array, which the compiler interprets as the address of the first member.
Pointer (to anything) Ptr-ref (Receiver) Data-area (Sender) Whether receiving or sending, the argument should be the name of the variable that denotes the address of interest. The translator takes care of the extra level of indirection that is necessary to allow CICS to update the pointer.
Note: Receiver is where data is being received from CICS; Sender is where data is being passed to CICS.