/sys$common/syshlp/HELPLIB.HLB  —  CRTL  Feature-Test Macros
    Feature-test macros provide a means for writing portable
    programs. They ensure that the C RTL symbolic names used
    by a program do not clash with the symbolic names supplied by the
    implementation.

    The C RTL header files are coded to support the use of
    a number of feature-test macros. When an application defines a
    feature-test macro, the 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
    C RTL header files define symbols without restriction.

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

    o  Standards

    o  Multiple-version support

    o  Compatibility

1  –  Standards Macros

    The C RTL implements parts of the following standards:

    o  X/Open CAE Specification, System Interfaces and Headers, Issue
       4, Version 2, also known as XPG4 V2.

    o  X/Open CAE Specification, System Interfaces and Headers, Issue
       4, also known as XPG4.

    o  Standard for Information Technology - Portable Operating
       System Interface (POSIX) - Part 1: System Application Program
       Interface (API)-Amendment 2: Threads Extension [C Language],
       also known as POSIX 1003.1c-1995 or IEEE 1003.1c-1995.

    o  ISO/IEC 9945-2:1993 - Information Technology - Portable
       Operating System Interface (POSIX) - Part 2: Shell and
       Utilities, also known as ISO POSIX-2.

    o  ISO/IEC 9945-1:1990 - Information Technology - Portable
       Operating System Interface (POSIX) - Part 1: System
       Application Programming Interface (API) (C Language), also
       known as ISO POSIX-1.

    o  ANSI/ISO/IEC 9899:1999 - The C99 standard, published by ISO in
       December, 1999 and adopted as an ANSI standard in April, 2000.

    o  ISO/IEC 9899:1990-1994 - Programming Languages - C, Amendment
       1: Integrity, also known as ISO C, Amendment 1.

    o  ISO/IEC 9899:1990 - Programming Languages - C, also known as
       ISO C. The normative part is the same as X3.159-1989, American
       National Standard for Information Systems - Programming
       Language C, also known as ANSI C.

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.

    Features not defined by one of the previously named standards are
    considered VSI 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 VSI C extensions.

2.1  –  XOPEN SOURCE EXTENDED

    Makes visible XPG4-extended features, including traditional UNIX
    based interfaces not previously adopted by X/Open.

    Standard Selected: XPG4 V2

    Other Standards Implied: XPG4, ISO POSIX-2, ISO POSIX-1, ANSI C

2.2  –  XOPEN SOURCE

    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.

    Notes:

    o  Where 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.

    o  Where 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.

    Standard Selected: XPG4

    Other Standards Implied: XPG4, ISO POSIX-2, ISO POSIX-1, ANSI C

2.3  –  POSIX C SOURCE==199506

    Header files defined by ANSI C make visible those symbols
    required by IEEE 1003.1c-1995.

    Standard Selected: IEEE 1003.1c-1995

    Other Standards Implied: ISO POSIX-2, ISO POSIX-1, ANSI C

2.4  –  POSIX C SOURCE==2

    Header files defined by ANSI C make visible those symbols
    required by ISO POSIX-2 plus those required by ISO POSIX-1.

    Standard Selected: ISO POSIX-2

    Other Standards Implied: ISO POSIX-1, ANSI C

2.5  –  POSIX C SOURCE==1

    Header files defined by ANSI C make visible those symbols
    required by ISO POSIX-1.

    Standard Selected: ISO POSIX-1

    Other Standards Implied: ANSI C

2.6  –  STDC VERSION ==199409

    Makes ISO C Amendment 1 symbols visible.

    Standard Selected: ISO C Amendment 1

    Other Standards Implied: ANSI C

2.7  –  ANSI C SOURCE

    Makes ANSI C standard symbols visible.

    Standard Selected: ANSI C

    Other Standards Implied: None.

2.8  –  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 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:

    o  The fdopen function is an ISO POSIX-1 extension to <stdio.h>.
       Therefore, <stdio.h> defines fdopen only if one or more of the
       following is true:

       -  The program including it is not compiled in strict ANSI C
          mode (/STANDARD=ANSI89).

       -  _POSIX_C_SOURCE is defined as 1 or greater.

       -  _XOPEN_SOURCE is defined.

       -  _XOPEN_SOURCE_EXTENDED is defined.

    o  The popen function is an ISO POSIX-2 extension to <stdio.h>.
       Therefore, <stdio.h> defines popen only if one or more of the
       following is true:

       -  The program including it is not compiled in strict ANSI C
          mode (/STANDARD=ANSI89).

       -  _POSIX_C_SOURCE is defined as 2 or greater.

       -  _XOPEN_SOURCE is defined.

       -  _XOPEN_SOURCE_EXTENDED is defined.

    o  The getw function is an X/Open extension to <stdio.h>.
       Therefore, <stdio.h> defines getw only if one or more of the
       following is true:

       -  The program is not compiled in strict ANSI C mode
          (/STANDARD=ANSI89).

       -  _XOPEN_SOURCE is defined.

       -  _XOPEN_SOURCE_EXTENDED is defined.

    o  The X/Open Extended symbolic constants _SC_PAGESIZE,
       _SC_PAGE_SIZE, _SC_ATEXIT_MAX, and _SC_IOV_MAX were added
       to <unistd.h> to support the sysconf function. However, these
       constants are not defined by _POSIX_C_SOURCE.

       The <unistd.h> header file defines these constants only if
       a program does not define _POSIX_C_SOURCE and does define
       _XOPEN_SOURCE_EXTENDED.

       If _POSIX_C_SOURCE is defined, these constants are not visible
       in <unistd.h>. Note that _POSIX_C_SOURCE is defined only for
       programs compiled in strict ANSI C mode.

    o  The fgetname function is a C RTL extension to
       <stdio.h>. Therefore, <stdio.h> defines fgetname only
       if the program is not compiled in strict ANSI C mode
       (/STANDARD=ANSI89).

    o  The macro _PTHREAD_KEYS_MAX is defined by POSIX 1003.1c-1995.
       This macro is made visible in <limits.h> when compiling for
       this standard with _POSIX_C_SOURCE == 199506 defined, or
       by default when compiling without any standards-defining,
       feature-test macros.

    o  The macro WCHAR_MAX defined in <wchar.h> is required by ISO C
       Amendment 1 but not by XPG4. Therefore:

       -  Compiling for ISO C Amendment 1 makes this symbol visible,
          but compiling for XPG4 compliance does not.

       -  Compiling for both ISO C Amendment 1 and XPG4 makes this
          symbol visible.

       Similarly, the functions wcsftime and wcstok in <wchar.h>
       are defined slightly differently by the ISO C Amendment 1 and
       XPG4:

       -  Compiling for ISO C Amendment 1 makes the ISO C Amendment 1
          prototypes visible.

       -  Compiling for XPG4 compliance makes the XPG4 prototypes
          visible.

       -  Compiling for both ISO C Amendment 1 and XPG4 selects the
          ISO C prototypes because conflicts resulting from this mode
          of compilation resolve in favor of ISO C.

       -  Compiling without any standard selecting feature test
          macros makes ISO C Amendment 1 features visible.

       In this example, compiling with no standard-selecting
       feature-test macros makes WCHAR_MAX and the ISO C Amendment 1
       prototypes for wcsftime and wcstok visible.

    o  The wcswidth and wcwidth functions are XPG4 extensions to
       ISO C Amendment 1. Their prototypes are in <wchar.h>.

       These symbols are visible if:

       -  Compiling for XPG4 compliance by defining _XOPEN_SOURCE or
          _XOPEN_SOURCE_EXTENDED.

       -  Compiling for DEC C Version 4.0 compatibility or on pre-
          OpenVMS Version 7.0 systems.

       -  Compiling with no standard-selecting feature-test macros.

       -  Compiling for both ISO C Amendment 1 and XPG4 compilance
          because these symbols are XPG4 extensions to ISO C
          Amendment 1.

       Compiling for strict ISO C Amendment 1 does not make them
       visible.

3  –  Multiple-Version-Support Macro

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

    To override the value of __VMS_VER, define __VMS_VER_OVERRIDE  on
    the compiler command line. Defining __VMS_VER_OVERRIDE without a
    value sets __VMS_VER to the maximum value.

4  –  Compatibility Modes

    The following predefined macros are used to select header-file
    compatibility with previous versions of DEC C or the OpenVMS
    operating system:

    o  _DECC_V4_SOURCE

    o  _VMS_V6_SOURCE

    There are two types of incompatibilities that can be controlled
    in the header files:

    o  To conform to standards, some changes are source-code
       incompatible but binary compatible. To select DEC C Version
       4.0 source compatibility, use the _DECC_V4_SOURCE macro.

    o  Other changes to conform to standards introduce a binary or
       run-time incompatibility.

       In general, programs that recompile get new behaviors. In
       these cases, use the _VMS_V6_SOURCE feature test macro to
       retain previous behaviors.

       However, for the exit, kill, and wait functions, the OpenVMS
       Version 7.0 changes to make these routines ISO POSIX-1
       compliant were considered too incompatible to become the
       default. Therefore, in these cases the default behavior is
       the same as on pre-OpenVMS Version 7.0 systems. To access the
       versions of these routines that comply with ISO POSIX-1, use
       the _POSIX_EXIT feature test macro.

    The following examples help clarify the use of these macros:

    o  To conform to the ISO POSIX-1 standard, typedefs for the
       following have been added to <types.h>:

          dev_t         off_t
          gid_t         pid_t
          ino_t         size_t
          mode_t        ssize_t
          nlink_t       uid_t

       Previous development environments using a version of DEC C
       earlier than Version 5.2 may have compensated for the lack
       of these typedefs in <types.h> by adding them to another
       module. If this is the case on your system, then compiling
       with the <types.h> provided with DEC C Version 5.2 might cause
       compilation errors.

       To maintain your current environment and include the DEC C
       Version 5.2 <types.h>, compile with _DECC_V4_SOURCE defined.
       This will omit incompatible references from the DEC C Version
       5.2 headers. In <types.h>, for example, the previously listed
       typedefs will not be visible.

    o  As of OpenVMS Version 7.0, the C RTL getuid and
       geteuid functions are defined to return an OpenVMS UIC (user
       identification code) that contains both the group and member
       portions of the UIC. In previous versions of the DEC C RTL,
       these functions returned only the member number from the UIC
       code.

       Note that the prototypes for getuid and geteuid in <unistd.h>
       (as required by the ISO POSIX-1 standard) and in <unixlib.h>
       (for C RTL compatibility) have not changed. By default,
       newly compiled programs that call getuid and geteuid get
       the new definitions. That is, these functions will return
       an OpenVMS UIC.

       To let programs retain the pre-OpenVMS Version 7.0 behavior of
       getuid and geteuid, compile with the _VMS_V6_SOURCE feature-
       test macro defined.

    o  As of OpenVMS Version 7.0, the C RTL exit function is
       defined with ISO POSIX-1 semantics. As a result, the input
       status argument to exit takes a number between 0 and 255.
       (Prior to this, exit could take an OpenVMS condition code in
       its status parameter.)

       By default, the behavior for exit on OpenVMS systems is the
       same as before: exit accepts an OpenVMS condition code. To
       enable the ISO POSIX-1 compatible exit function, compile with
       the _POSIX_EXIT feature-test macro defined.

5  –  Curses and Socket Compatibility Macros

    The following feature-test macros are used to control the Curses
    and Socket subsets of the C RTL library:

    o  _BSD44_CURSES

       This macro selects the Curses package from the 4.4BSD Berkeley
       Software Distribution.

    o  _VMS_CURSES

       This macro selects a Curses package based on the VAX C
       compiler. This is the default Curses package.

    o  _SOCKADDR_LEN

       This macro is used to select 4.4BSD-compatible and XPG4 V2-
       compatible socket interfaces. These interfaces require support
       in your underlying TCP/IP software. Contact your TCP/IP vendor
       to inquire if the version of TCP/IP software you run supports
       4.4BSD sockets.

    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:

    o  Symbolic constants like AE, AL, AS, AM, BC, which represent
       pointers to termcap fields used by the BSD Curses package, are
       only visible in <curses.h> if _BSD44_CURSES is defined.

    o  The <socket.h> header file defines a 4.4BSD sockaddr structure
       only if _SOCKADDR_LEN or _XOPEN_SOURCE_EXTENDED is defined.
       Otherwise, <socket.h> defines a pre-4.4BSD sockaddr structure.
       If _SOCKADDR_LEN is defined and _XOPEN_SOURCE_EXTENDED is not
       defined,

       The <socket.h> header file also defines an osockaddr
       structure, which is a 4.3BSD sockaddr structure to be used
       for compatibility purposes. Since XPG4 V2 does not define
       an osockaddr structure, it is not visible in _XOPEN_SOURCE_
       EXTENDED mode.

6  –  2 GB File Size Macro

    The C RTL provides support for compiling applications to use file
    sizes and offsets that are 2 GB and larger. This is accomplished
    by allowing file offsets of 64-bit integers.

    The fseeko and ftello functions, which have the same behavior
    as fseek and ftell, accept or return values of type off_t, which
    allows for a 64-bit variant of off_t to be used.

    C RTL functions lseek, mmap, ftuncate, truncate, stat, fstat, and
    ftw can also accommodate a 64-bit file offset.

    The new 64-bit interfaces can be selected at compile time by
    defining the _LARGEFILE feature macro.

7  –  32-Bit UID and GID Macro (Integrity servers, Alpha)

    The C RTL supports 32-bit User Identification (UID) and Group
    Identification (GID). When an application is compiled to use
    32-bit UID/GID, the UID and GID are derived from the UIC as in
    previous versions of the operating system.

    To compile an application for 16-bit UID/GID support on systems
    that by default use 32-bit UIDs/GIDs, define the _DECC_SHORT_GID_
    T macro to 1.

    Not specifying _DECC_SHORT_GID_T provides long (32-bit) UID/GID.

    Compiling on older OpenVMS systems where long UID/GID is not
    supported, or compiling for legacy compatibility (_DECC_V4_SOURCE
    for VSI C Version 4 or _VMS_V6_SOURCE for OpenVMS Version 6),
    forces use of short (16-bit) UID/GID.

8  –  Standard-Compliant stat Structure (Integrity servers, Alpha)

    The C RTL supports an X/Open standard-compliant definition of
    the stat structure and associated definitions. To use these new
    definitions, applications must compile with the _USE_STD_STAT
    feature-test macro defined. Use of _USE_STD_STAT specifies long
    (32-bit) GIDs.

    When compiled with _USE_STD_STAT, the stat structure includes
    these changes:

    o  Type ino_t is defined as an unsigned quadword int. Without _
       USE_STD_STAT, it is an unsigned short.

    o  Type dev_t is defined as a 64-bit integer. Without _USE_STD_
       STAT, it is a 32-bit character pointer.

    o  Type off_t is defined as a 64-bit integer, as if the _
       LARGEFILE macro has been defined. Without _USE_STD_STAT, off_t
       is a 32-bit integer.

    o  Fields st_dev and st_rdev will have unique values per device.
       Without _USE_STD_STAT, uniqueness is not assured.

    o  Fields st_blksize and st_blocks are added. Without _USE_STD_
       STAT, these fields do not exist.

9  –  Using Legacy toupper and tolower Behavior (Integrity servers, Alpha)

    As of OpenVMS Version 8.3, to comply with the C99 ANSI standard
    and X/Open Specification, the _tolower and _toupper macros by
    default do not evaluate their parameter more than once. They
    simply call their respective tolower or toupper function. This
    avoids side effects (such as i++ or function calls) where the
    user can tell how many times an expression is evaluated.

    To retain the older, optimized behavior of the _tolower and _
    toupper macros, compile with /DEFINE=_FAST_TOUPPER. Then, as
    in previous releases, these macros optimize the call to avoid
    the overhead of a runtime call. However, the macro's parameter
    is evaluated more than once to determine how to calculate the
    result, possibly creating unwanted side effects.

10  –  Using Faster, Inlined Put and Get Functions (Integrity servers, Alpha)

    Compiling with the __UNIX_PUTC macro defined enables an
    optimization that sets the following I/O functions to use faster,
    inlined functions:

    fgetc
    fputc
    putc
    putchar
    fgetc_unlocked
    fputc_unlocked
    putc_unlocked
    putchar_unlocked

11  –  POSIX Style exit (Integrity servers, Alpha)

    The VSI C and C++ Version 7.1 and higher compilers have a
    /MAIN=POSIX_EXIT qualifier that defines the _POSIX_EXIT macro
    and causes the main program to call __posix_exit instead of exit
    when returning from the main program.

    This qualifier should be used with programs ported from UNIX that
    do not explicitly call exit and do not use OpenVMS specific exit
    codes.

    For older compilers, the following sample code can be used to
    force the existing main module to have a different name so that a
    simple main program will call it but force the exit status to be
    through the __posix_exit call.

    The replacement main function can be in a different module, so
    that /DEFINE="main=real_main" is all that is needed for modifying
    the build of the existing main function.

    #define _POSIX_EXIT 1

    #include <stdlib.h>

    int real_main(int argc, char **argv);

    /* Make sure POSIXized exit is used */
    int main(int argc, char **argv)
    {
    int ret_status;

       ret_status = real_main(argc, argv);

    exit (ret_status);
    }
    #define main real_main

    Unless your C program is intentionally using OpenVMS status codes
    for exit values, it is strongly recommended that both the _POSIX_
    EXIT macro be defined and, if needed, the /MAIN=POSIX_EXIT or the
    alternative main replacement be used so that DCL, BASH, and the
    accounting file get usable exit values.
Close Help