[an error occurred while processing this directive]
HP OpenVMS SystemsC Programming Language |
Compaq C
|
Previous | Contents | Index |
A Compaq PL/I variable with the EXTERNAL attribute corresponds to a FORTRAN common block and to a Compaq C extern variable in the common_block external model. Example 3-16 and Example 3-17 show how a program section is shared between Compaq C and Compaq PL/I.
A PL/I EXTERNAL CHARACTER attribute corresponds to a Compaq C extern char variable, but PL/I character strings are not necessarily null-terminated. In Example 3-16, Compaq C and Compaq PL/I use the same variable to manipulate the character string that resides in a program section named XYZ.
Example 3-16 Sharing Data with a PL/I Program in Named Program Sections |
---|
/* PL/I program PRSTRING.PLI contains the following lines of code: */ PRSTRING: PROCEDURE; DECLARE XYZ EXTERNAL CHARACTER(20); PUT SKIP LIST(XYZ); RETURN; END PRSTRING; /* End of PL/I program */ /* Compaq C program STRING.C contains the following lines of * * code: */ main(void) { extern char xyz[20]; strncpy(xyz,"This is a string ", sizeof xyz); prstring(); } |
The PL/I procedure PRSTRING writes out the contents of the external variable XYZ .
PL/I also has a structure type similar (in its internal representation) to the struct keyword in Compaq C. Moreover, Compaq PL/I can output aggregates, such as structures and arrays, in fairly simple stream-output statements; consider Example 3-17.
Example 3-17 Sharing Data with a PL/I Program in a Compaq C Structure |
---|
/* PL/I program FNUM.PLI contains the following lines of code: */ FNUM: PROCEDURE; /* EXTERNAL STRUCTURE CONTAINING THREE INTEGERS */ DECLARE 1 NUMBERS EXTERNAL, 2 FIRST FIXED(31), 2 SECOND FIXED(31), 2 THIRD FIXED(31); PUT SKIP LIST('Contents of structure:',NUMBERS); RETURN; END FNUM; /* End of PL/I program */ /* Compaq C program NUMBERS.C contains the following lines of * * code: */ struct xs { int first; int second; int third; }; main() { extern struct xs numbers; numbers.first = 1; numbers.second = 2; numbers.third = 3; fnum(); } |
The PL/I procedure FNUM writes out the complete contents of the external structure NUMBERS; the structure members are written out in the order of their storage in memory, which is the same as for a Compaq C structure.
In a MACRO program, the .PSECT directive sets up a separate program section that can store data or MACRO instructions. The attributes in the .PSECT directive describe the contents of the program section.
Example 3-18 shows how to set up a psect in a MACRO program that allows data to be shared with a Compaq C program.
Example 3-18 Sharing Data with a MACRO Program in a Compaq C Structure |
---|
; MACRO source file SET_VALUE.MAR contains the following lines of code: .entry set_value,^M<> movl #1,first movl #2,second movl #3,third ret .psect example pic,usr,ovr,rel,gbl,noshr,- noexe,rd,wrt,novec,long first: .blkl second: .blkl third: .blkl .end ; End of MACRO source file /* Compaq C program NUMBERS.C contains the following lines of * * code: */ #pragma extern_model common_block struct xs { int first; int second; int third; } example; main() { set_value(); printf("example.first = %d\n", example.first); printf("example.second = %d\n", example.second); printf("example.third = %d\n", example.third); } |
The MACRO program initializes the locations first, second, and third in the psect named example and passes these values to the Compaq C program. The locations are referenced in the Compaq C program as members of the external structure named example .
Also, note the #pragma extern_model common_block preprocessor directive. This directive sets the model for external variables to the common_block model, which is the one used by VAX C. The default external model for Compaq C is the relaxed_refdef model. For more information on the #pragma extern_model common_block preprocessor directive, see Section 5.4.5.
The OpenVMS Run-Time Library (RTL) is a library of prewritten, commonly used routines that perform a wide variety of functions. These routines are grouped according to the types of tasks they perform, and each group has a prefix that identifies those routines as members of a particular OpenVMS RTL facility. Table 3-10 lists all the language-independent, run-time library facility prefixes and the types of tasks each facility performs.
The OpenVMS run-time library routines are documented in detail in the following operating system documentation:
System services are prewritten system routines that perform a variety of tasks, such as controlling processes, communicating among processes, and coordinating I/O.
Unlike the OpenVMS Run-Time Library (RTL) routines, which are divided into groups by facility, all system services share the same facility prefix (SYS$). However, these services are logically divided into groups that perform similar tasks. Table 3-11 describes these groups.
System services are documented in detail in the OpenVMS System Services Reference Manual.
The routines that provide a programming interface to various OpenVMS utilities are described in the OpenVMS Utility Routines Manual.
The basic steps for calling routines are the same whether you are calling a routine written in Compaq C, a routine written in some other OpenVMS language, a system service, or an OpenVMS Run-Time Library (RTL) routine. The following sections outline the procedures for calling non-Compaq C routines.
Before calling an external routine, you must first determine whether the call should be a procedure call or a function call. Call a routine as a procedure if it does not return a value. Call a routine as a function if it returns any type of value.
To call an external routine or system routine, you need to declare it as an external function and to declare the names, data types, and passing mechanisms of its arguments. Arguments can be either required or optional.
Include the following information in a routine declaration:
The following example shows how to declare an external routine and its arguments:
char func_name (int x, char y); |
Header files are available to declare commonly used external routines. Using them will save you a lot of work. See Sections 1.3.1.1 and 1.3.1.2 in this manual for information on listing and including header files.
After declaring an external routine, you can invoke it. To invoke a function, you must specify the name of the routine being invoked and all arguments required for that routine. Make sure the data types for the actual arguments you are passing coincide with those of the parameters you declared earlier, and with those declared in the routine. The following example shows how to invoke the function declared in Section 3.7.2:
ret_status = func_name(1,'a'); |
All system routine arguments are described in terms of the following information:
OpenVMS usages are data structures that are layered on the standard OpenVMS data types. For example, the OpenVMS usage mask_longword signifies an unsigned longword integer that is used as a bit mask, and the OpenVMS usage floating_point represents any OpenVMS floating-point data type. Table 3-12 lists all the OpenVMS usages and the Compaq C types you need to implement them.
If a system routine argument is optional, it will be indicated in the format section of the routine description in one of two ways, as follows:
If the comma appears outside the brackets, you must pass a 0 by value to indicate the place of the omitted argument. If the comma appears inside the brackets, you can omit the argument if it is the last argument in the list.
For more information, see the OpenVMS Programming Interfaces: Calling a System Routine manual. This manual describes the OpenVMS programming interface and defines the standard conventions to call an OpenVMS system routine from a user procedure. The Alpha and VAX data type implementations for various high-level languages are also presented.
Previous | Next | Contents | Index |