DEC C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index

1.5 Feature-Test Macros for Header-File Control

Feature-test macros provide a means for writing portable programs. They ensure that the DEC C RTL symbolic names used by a program do not clash with the symbolic names supplied by the implementation.

The DEC C Run-time Library header files are coded to support the use of a number of feature-test macros. When an application defines a feature-test macro, the DEC C RTL header files supply the symbols and prototypes defined by that feature-test macro and nothing else. If a program does not define such a macro, the DEC C RTL header files define symbols without restriction.

The feature-test macros supported by the DEC C Run-time Library fall into three broad categories for controlling the visibility of symbols in header files according to the following:

1.5.1 Standards Macros

The DEC C Run-time Library implements parts of the following standards:

1.5.2 Selecting a Standard

You can define a feature-test macro to select each standard. You can do this either with a #define preprocessor directive in your C source before the inclusion of any header file, or with the /DEFINE qualifier on the CC command line.

Table 1-4 lists and describes the DEC C RTL feature-test macros that control standards support.

macro)
Table 1-4 Feature Test Macros - Standards
Macro Name Standard Selected Other Standards Implied Description
_xopen_source_extended XPG4 V2 XPG4, ISO POSIX-2, ISO POSIX-1, ANSI C Makes visible XPG4-extended features, including traditional UNIX-based interfaces not previously adopted by X/Open.
_xopen_source XPG4 ISO POSIX-2, ISO POSIX-1, ANSI C Makes visible XPG4 standard symbols and causes _posix_c_source to be set to 2 if it is not already defined with a value greater than 2. 1, 2
_posix_c_source :=,=199506 IEEE 1003.1c-1995 ISO POSIX-2, ISO POSIX-1, ANSI C Header files defined by ANSI C make visible those symbols required by IEEE 1003.1c-1995.
_posix_c_source :=,= 2 ISO POSIX-2 ISO POSIX-1, ANSI C Header files defined by ANSI C make visible those symbols required by ISO POSIX-2 plus those required by ISO POSIX-1.
_posix_c_source :=,= 1 ISO POSIX-1 ANSI C Header files defined by ANSI C make visible those symbols required by ISO POSIX-1.
__stdc_version__ :=,=199409 ISO C amdt 1 ANSI C Makes ISO C amendment 1 symbols visible.
_ansi_c_source ANSI C --- Makes ANSI C standard symbols visible.


1Where the ISO C Amendment 1 includes symbols not specified by XPG4, defining __stdc_version__ :=,= 199409 and _xopen_source (or _xopen_source_extended) selects both ISO C and XPG4 APIs. Conflicts that arise when compiling with both XPG4 and ISO C Amendment 1 resolve in favor of ISO C Amendment 1.
2Where XPG4 extends the ISO C Amendment 1, defining _xopen_source or _xopen_source_extended selects ISO C APIs as well as the XPG4 extensions available in the header file. This mode of compilation makes XPG4 extensions visible.

Features not defined by one of the previously named standards are considered DEC C extensions and are selected by not defining any standards-related, feature-test macros.

If you do not explicitly define feature test macros to control header file definitions, you implicitly include all defined symbols as well as DEC C extensions.

1.5.3 Interactions with the /STANDARD Qualifier

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 DEC 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:

1.5.4 Multiple-Version-Support Macro

By default, the header files enable APIs in the DEC 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 DEC C User's Guide for OpenVMS Systems. For example, compiling on OpenVMS Version 6.2 causes only DEC 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 DEC 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:

  1. Define a logical DECC$SHR to point to the old version of DECC$SHR. The compiler uses a table from DECC$SHR to perform routine name prefixing.
  2. Define __vms_ver appropriately, either with the /DEFINE qualifier or with a combination of the #undef and #define preprocessor directives. With /DEFINE, you may need to disable the warning regarding redefinition of a predefined macro.

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:

1.5.6 Curses and Socket Compatibility Macros

The following feature-test macros are used to control the curses and socket subsets of the DEC 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:

1.6 Input and Output on OpenVMS Systems

After you learn how to link with the DEC C RTL and call DEC C functions and macros, you can use the DEC 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 DEC 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 DEC C Standard I/O and UNIX I/O functions and macros use the RMS functions. Since the DEC 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 DEC C RTL adds functionality to this original specification. Since, as implemented in the DEC C RTL, the Standard I/O functions recognize line terminators, the DEC C RTL Standard I/O functions are particularly useful for text manipulation. The DEC 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 DEC C RTL adds functionality to the original specification. The UNIX I/O functions, as implemented in DEC C, are particularly useful for manipulating binary data. The DEC C RTL also implements some of the UNIX I/O functions as preprocessor defined macros.

The DEC 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 DEC 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



Previous Next Contents Index