![]() |
Software > OpenVMS Systems > Documentation > 731final > 5841 ![]() HP OpenVMS Systems Documentation |
![]() |
OpenVMS Programming Concepts Manual
18.5.2 Passing Arguments by ReferenceWhen your program passes arguments using the by reference mechanism, the argument list entry contains the address of the location that contains the value of the argument. For example, if variable x is allocated at location 1000, the argument list entry will contain 1000, the address of the value of x. On Alpha processors, the address is sign-extended from 32 bits to 64 bits. Most languages (but not C) pass scalar data by reference by default. Therefore, if you simply specify x in the CALL statement or function invocation, the language automatically passes the value stored at the location allocated to x to the OpenVMS system routine. A VAX BLISS program calls a procedure using the by-reference mechanism as follows:
The equivalent VAX MACRO code is as follows:
A C language program calls a procedure using the by-reference mechanism as follows:
18.5.3 Passing Arguments by DescriptorWhen a procedure specifies that an argument is passed by descriptor, the argument list entry must contain the address of a descriptor for the argument. For more information about OpenVMS Alpha 64-bit descriptors, refer to Chapter 11. On Alpha processors, the address is sign-extended from 32 bits to 64 bits. This mechanism is used to pass more complicated data. For both Alpha and VAX systems, a descriptor includes at least the following fields:
The OpenVMS Calling Standard describes these fields in greater detail. OpenVMS high-level languages include extensions for passing arguments by descriptor. When you specify by descriptor in these languages, the compiler creates the descriptor, defines its fields, and passes the address of the descriptor to the OpenVMS system routine. In some languages, by descriptor is the default passing mechanism for certain types of arguments, such as character strings. For example, the default mechanism for passing strings in BASIC is by descriptor.
The default mechanism for passing strings in COBOL, however, is by reference. Therefore, when passing a string argument to an OpenVMS system routine from a COBOL program, you must specify BY DESCRIPTOR for the string argument in the CALL statement.
In VAX MACRO or BLISS, you must define the descriptor's fields explicitly and push its address onto the stack. Following is the VAX MACRO code that corresponds to the previous examples.
The equivalent BLISS code looks like this:
A C language program calls a procedure using the by-descriptor mechanism as follows:
18.6 Passing Scalars as ArgumentsWhen you are passing an input scalar value to an OpenVMS system routine, you usually pass it either by reference or by value. You usually pass output scalar arguments by reference to OpenVMS system routines. An output scalar argument is the address of a location where some scalar output of the routine will be stored. 18.7 Passing Arrays as ArgumentsArrays are passed to OpenVMS system routines by reference or by descriptor. Sometimes the routine knows the length and dimensions of the array to be received, as in the case of the table passed to LIB$CRC_TABLE. Arrays such as this are normally passed by reference. In other cases, the routine actually analyzes and operates on the input array. The routine does not necessarily know the length or dimensions of such an input array, so a descriptor is necessary to provide the information the routine needs to describe the array accurately. 18.8 Passing Strings as ArgumentsStrings are passed by descriptor to OpenVMS system routines. Table 18-5 lists the string-passing descriptors recognized by a system routine.
An OpenVMS system routine writes strings according to the following types of semantics:
18.9 Combinations of Descriptor Class and Data TypeSome combinations of descriptor class and data type are not permitted, either because they are not meaningful or because the calling standard does not recognize them. Possibly, the same function can be performed with more than one combination. This section describes the restrictions on the combinations of descriptor classes and data types. These restrictions help to keep procedure interfaces simple by allowing a procedure to accept a limited set of argument formats without sacrificing functional flexibility. The tables in Figures 18-9, 18-10, and 18-11 show all possible combinations of descriptor classes and data types. For example, Figure 18-9 shows that your program can pass an argument to an OpenVMS system routine whose descriptor class is DSC$K_CLASS_A (array descriptor) and whose data type is unsigned byte (DSC$K_DTYPE_BU). The calling standard does not permit your program to pass an argument whose descriptor class is DSC$K_CLASS_D (dynamic string) and whose data type is unsigned byte. A descriptor with data type DSC$K_DTYPE_DSC (24) points to a descriptor that has class DSC$K_CLASS_D (2) and data type DSC$K_DTYPE_T (14). All other class and data type combinations in the target descriptor are reserved for future definition in the standard. The scale factor for DSC$K_CLASS_SD is always a decimal data type. It does not vary with the data type of the data described by the descriptor. For DSC$K_CLASS_UBS and DSC$K_CLASS_UBA, the length field specifies the length of the data field in bits. For example, if the data type is unsigned word (DSC$K_DTYPE_WU), DSC$W_LENGTH equals 16. Figure 18-9 Atomic Data Types and Descriptor Classes ![]() Figure 18-10 String Data Types and Descriptor Classes ![]() Figure 18-11 Miscellaneous Data Types and Descriptor Classes ![]() 18.10 Return of the Function ValueA function is a routine that returns a single value to the calling routine. The function value represents the value of the expression in the return statement. As specified by the calling standard, a function value may be returned as an actual value in R0.On VAX systems, if the actual function value returned is greater than 32 bits, then both R0 and R1 should be used. On Alpha systems, if the actual function returned is a floating-point value, the floating-point value is returned either in F0 or in both F0 and F1. A standard function must return its function value by one of the following mechanisms:
These mechanisms are the standard return convention because they support the language-independent data types. For information about condition values returned in R0, see Section 18.11. 18.11 Return of the Condition ValueAn OpenVMS system routine can indicate success or failure to the calling program by returning a condition value. In addition, an error condition to the calling program can return as a condition value in R0 or by error signaling. A condition value in R0, also called a return status or completion code, is either a success (bit 0 = 1) value or an error condition (bit 0 = 0) value. In an error condition value, the low-order 3 bits specify the severity of the error (see Figure 18-12). Bits <27:16> contain the facility number, and bits <15:3> indicate the particular condition. Bits <31:28> are the control field. When the called procedure returns a condition value, the calling program can test R0 and choose a recovery path. A general guideline to follow when testing for success or failure is that all success codes have odd values and all error codes have even values. Figure 18-12 Condition Value Format ![]() When the completion code is signaled, the calling program must establish a handler to get control and take appropriate action. (See the OpenVMS Programming Concepts Manual or the OpenVMS Calling Standard for a description of signaling and condition handling and for more information about the condition value.)
Chapter 19
|
fac$symbol |
The elements that make up this format represent the following:
fac | A 2- or 3-character facility name | |
symbol | A 1- to 27-character symbol |
The facility names are maintained in a systemwide Compaq registry. A unique, 12-bit facility number is assigned to each facility name for use in (1) condition value symbols, and (2) condition values in procedure return status codes, signaled conditions, and messages. The high-order bit of this number is 0 for facilities assigned by Compaq and 1 for those assigned by Application Project Services (APS) and customers. For further information, refer to the OpenVMS Calling Standard.
The run-time library facility names are as follows:
CVT$ | Convert routines | |
DTK$ | DECtalk routines | |
LIB$ | Library routines | |
MTH$ | Mathematics routines | |
OTS$ | General-purpose routines | |
PPL$ | Parallel processing routines | |
SMG$ | Screen management routines | |
STR$ | String-handling routines |
Previous | Next | Contents | Index |