United States |
Previous | Contents | Index |
The /STANDARD qualifier selects the dialect of the C language supported.
With the exception of /STANDARD=ANSI89 and /STANDARD=ISOC94, the selection of C dialect and the selection of Compaq C RTL APIs to use are independent choices. All other values for /STANDARD cause the entire set of APIs to be available, including extensions.
Specifying /STANDARD=ANSI89 restricts the default API set to the ANSI C set. In this case, to select a broader set of APIs, you must also specify the appropriate feature-test macro. To select the ANSI C dialect and all APIs, including extensions, undefine __hide_forbidden_names before including any header file.
Compiling with /STANDARD=ISOC94 sets __stdc_version__ to 199409. Conflicts that arise when compiling with both XPG4 and ISO C Amendment 1 resolve in favor of ISO C Amendment 1. XPG4 extensions to ISO C Amendment 1 are selected by defining _xopen_source .
The following examples help clarify these rules:
By default, the header files enable APIs in the Compaq C RTL provided by the version of the operating system on which the compilation occurs. This is accomplished by the predefined setting of the __vms_ver macro, as described in the Compaq C User's Guide for OpenVMS Systems. For example, compiling on OpenVMS Version 6.2 causes only Compaq C RTL APIs from Version 6.2 and earlier to be made available.
Another example of the use of the __vms_ver macro is support for the 64-bit versions of Compaq C RTL functions available with OpenVMS Alpha Version 7.0 and higher. In all header files, functions that provide 64-bit support are conditionalized so that they are visible only if __vms_ver indicates a version of OpenVMS that is greater than or equal to 7.0.
To target an older version of the operating system, do the following:
Targeting a newer version of the operating system might not always be
possible. For some versions, you can expect that the new DECC$SHR.EXE
will require new features of the operating system that are not present.
For such versions, the defining if the logical DECC$SHR in Step 1 would
cause the compilation to fail.
1.5.5 Compatibility Modes
The following predefined macros are used to select header-file compatibility with previous versions of DEC C) or the OpenVMS operating system:
There are two types of incompatibilities that can be controlled in the header files:
The following examples help clarify the use of these macros:
dev_t
gid_t
ino_t
mode_t
nlink_t
off_t
pid_t
size_t
ssize_t
uid_t
The following feature-test macros are used to control the curses and socket subsets of the Compaq C RTL library:
Strict XPG4 V2 compliance requires the 4.4BSD-compatible socket interface. Therefore, if _xopen_source_extended is defined on OpenVMS Version 7.0 or higher, _sockaddr_len is defined to be 1.
The following examples help clarify the use of these macros:
After you learn how to link with the Compaq C RTL and call Compaq C functions and macros, you can use the Compaq C RTL for its primary purpose: input/output (I/O).
Since every system has different methods of I/O, familiarize yourself with the OpenVMS-specific methods of file access. In this way, you will be equipped to predict functional differences when porting your source program from one operating system to another.
Figure 1-2 shows the I/O methods available with the Compaq C RTL. The OpenVMS system services communicate directly with the OpenVMS operating system, so they are closest to the operating system. The OpenVMS Record Management Services (RMS) functions use the system services, which manipulate the operating system. The Compaq C Standard I/O and UNIX I/O functions and macros use the RMS functions. Since the Compaq C RTL Standard I/O and UNIX I/O functions and macros must go through several layers of function calls before the system is manipulated, they are furthest from the operating system.
Figure 1-2 I/O Interface from C Programs
The C programming language was developed on the UNIX operating system, and the Standard I/O functions were designed to provide a convenient method of I/O that would be powerful enough to be efficient for most applications, and also be portable so that the functions could be used on any system running C language compilers.
The Compaq C RTL adds functionality to this original specification. Since, as implemented in the Compaq C RTL, the Standard I/O functions recognize line terminators, the Compaq C RTL Standard I/O functions are particularly useful for text manipulation. The Compaq C RTL also implements some of the Standard I/O functions as preprocessor defined macros.
In a similar manner, the UNIX I/O functions originally were designed to provide a more direct access to the UNIX operating systems. These functions were meant to use a numeric file descriptor to represent a file. A UNIX system represents all peripheral devices as files to provide a uniform method of access.
The Compaq C RTL adds functionality to the original specification. The UNIX I/O functions, as implemented in Compaq C, are particularly useful for manipulating binary data. The Compaq C RTL also implements some of the UNIX I/O functions as preprocessor defined macros.
The Compaq C RTL includes the Standard I/O functions that should exist on all C compilers, and also the UNIX I/O functions to maintain compatibility with as many other implementations of C as possible. However, both Standard I/O and UNIX I/O use RMS to access files. To understand how the Standard I/O and UNIX I/O functions manipulate RMS formatted files, learn the fundamentals of RMS. See Section 1.6.1 for more information about Standard I/O and UNIX I/O in relationship to RMS files. For an introduction to RMS, see the Guide to OpenVMS File Applications.
Before deciding which method is appropriate for you, first ask this question: Are you concerned with UNIX compatibility or with developing code that will run solely under the OpenVMS operating system?
If you are writing system-level software, you may need to access the OpenVMS operating system directly through calls to system services. For example, you may need to access a user-written device driver directly through the Queue I/O Request System Service ($QIO). To do this, use the OpenVMS level of I/O; this level is recommended if you are an experienced OpenVMS programmer. For examples of programs that call OpenVMS system services, see the Compaq C User's Guide for OpenVMS Systems.
You may never use the RMS or the OpenVMS system services. The Standard I/O and UNIX I/O functions are efficient enough for a large number of applications. Figure 1-3 shows the dependency of the Standard I/O and the UNIX I/O functions on RMS, and the various methods of I/O available to you.
Figure 1-3 Mapping Standard I/O and UNIX I/O to RMS
To understand the capabilities and the restrictions of the Standard I/O and UNIX I/O functions and macros, you need to understand VAX Record Management Services (RMS).
RMS supports the following file organizations:
Sequential files have consecutive records with no empty records in between; relative files have fixed-length cells that may or may not contain a record; and indexed files have records that contain data, carriage-control information, and keys that permit various orders of access.
The Compaq C RTL functions can access only sequential files. If you wish to use the other file organizations, you must use the RMS functions. For more information about the RMS functions, see the Compaq C User's Guide for OpenVMS Systems.
RMS is not concerned with the contents of records, but it is concerned about the record format, which is the way a record physically appears on the recording surface of the storage medium.
RMS supports the following record formats:
You can specify a fixed-length record format at the time of file creation. This means that all records occupy the same amount of space in the file. You cannot change the record format once you create the file.
The length of records in variable length, VFC, and stream file formats can vary up to a maximum size that must be specified when you create the file. With variable-length record or VFC format files, the size of the record is held in a header section at the beginning of the data record. With stream files, RMS terminates the records when it encounters a specific character, such as a carriage-control or line-feed character. Stream files are useful for storing text.
RMS allows you to specify carriage-control attributes for records in a file. Such attributes include the implied carriage-return or the FORTRAN formatted records. RMS interprets these carriage controls when the file is output to a terminal, a line printer, or other device. The carriage-control information is not stored in the data records.
By default, files inherit the RMS record format, maximum record size
and record attributes, from the previous version of the file, if one
exists; to an OpenVMS system programmer, the inherited
attributes are known as fab$b_rfm, fab$w_mrs and fab$b_rat. If no
previous versions exist, the newly created file defaults to stream
format with line-feed record separator and implied carriage-return
attributes. (This manual refers to this type of file as a stream
file.) You can manipulate stream files using the Standard I/O and
the UNIX I/O functions of the Compaq C RTL. When using these files and
fixed-record files with no carriage control, there is no restriction on
the ability to
seek to any random byte of the file using the
fseek
or the
lseek
functions. However, if the file has one of the other RMS record
formats, such as variable-length record format, then these functions,
due to RMS restrictions, can seek only to record boundaries. Use the
default VAX stream format unless you need to create or access files to
be used with other VAX languages or utilities.
1.6.2 Access to RMS Files
RMS sequential files can be opened in record mode or stream mode. By default, STREAM_LF files are opened in stream mode; all other file types are opened in record mode. When opening a file, you can override these defaults by specifying the optional argument "ctx=rec" to force record mode, or "ctx=stm" to force stream mode. RMS relative and indexed files are always opened in record mode. The access mode determines the behavior of various I/O functions in the Compaq C RTL.
One of the file types defined by RMS is an "RMS-11 stream" format file, corresponding to a value of FAB$C_STM for the record format. The definition of this format is such that the RMS record operation SYS$GET removes leading null bytes from each record. Because this file type is processed in record mode by the Compaq C RTL, it is unsuitable as a file format for binary data unless it is explicitly opened with "ctx=stm", in which case the raw bytes of data from the file are returned.
In OpenVMS Version 7.0 the default LRL value on stream files was changed from 0 to 32767. This change caused significant performance degradation on certain file operations such as sort. This is no longer a problem. The Compaq C Run-Time Library now lets you define the logical DECC$DEFAULT_LRL to change the default record-length value on stream files. The Compaq C Run-Time Library first looks for this logical. If it is found and it translates to a numeric value between 0 and 32767, that value is used for the default LRL. To restore the behavior prior to OpenVMS Version 7.0, enter the following command:
|
Previous | Next | Contents | Index |
|