Skip to Main Content United States    
PRODUCTS SUPPORT SOLUTIONS SERVICES
COMPAQ SOFTWARE
Compaq C

Compaq C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index

1.3.5 Linking with the VAX C RTL /NOSYSSHR

This section applies to programs running on OpenVMS VAX Version 6.0 or higher.

For programs that currently link with the VAX C RTL object libraries using the /NOSYSSHR qualifier, you must specify /INCLUDE=CMA$TIS for the object library. Otherwise, several symbols will be undefined and the resulting image will not execute. In order to add this qualifier, you cannot use the LNK$LIBRARY logicals to link with the VAX C RTL object libraries. You must use a linker options file or list the VAX C RTL object libraries on the command line. For example:


$ LINK/NOSYSSHR PROG1, SYS$LIBRARY:VAXCRTL.OLB/LIBRARY/INCLUDE=CMA$TIS

1.4 Compaq C RTL Function Prototypes and Syntax

After learning how to link object modules and include header files, you must learn how to reference Compaq C functions in your program. The remaining chapters in this manual provide detailed descriptions of the Compaq C RTL functions.

1.4.1 Function Prototypes

In all chapters, the syntax describing each function follows the standard convention for defining a function. This syntax is called a function prototype (or just prototype). The prototype is a compact representation of the order of a function's arguments (if any), the types of the arguments, and the type of the value returned by a function. The use of prototypes is recommended.

If the return value of the function cannot be easily represented by a C data-type keyword, look for a description of the return values in the explanatory text. The prototype descriptions provide insight into the functionality of the function. These descriptions may not describe how to call the function in your source code.

For example, consider the prototype for the feof function:

#include <stdio.h>
int feof(FILE *file_ptr);

This syntax shows the following information:

  • The feof prototype resides in the <stdio.h> header file. To use feof , you must include this header file. (Declaring Compaq C RTL functions yourself is not recommended.)
  • The feof function returns a value of data type int .
  • There is one argument, file_ptr, that is of type "pointer to FILE". FILE is defined in the <stdio.h> header file.

To use feof in a program, include <stdio.h> anywhere before the function call to feof , as in the following example:


#include <stdio.h>                 /* Include Standard I/O     */ 
 
main() 
{ 
 
    FILE *infile;                  /* Define a file pointer    */ 
       . 
       . 
       .                           /* Call the function feof   */ 
    while ( ! feof(infile) )       /* Until EOF reached        */ 
       {                           /* Perform file operations  */ 
          . 
          . 
          . 
       } 
} 

1.4.2 Syntax Conventions for Function Prototypes

Since some library functions take a varying number of parameters, syntax descriptions for function prototypes adhere to the following conventions:

  • Ellipses (...) are used to indicate a varying number of parameters.
  • In cases where the type of a parameter may vary, its type is not shown in the syntax.

Consider the printf syntax description:

#include <stdio.h>
int printf(const char *format_specification, ...);

The syntax description for printf shows that you can specify one or more optional parameters. The remaining information about printf parameters is in the description of the function.

1.4.3 UNIX Style File Specifications

The Compaq C RTL functions and macros often manipulate files. One of the major portability problems is the different file specifications used on various systems. Since many C applications are ported to and from UNIX systems, it is convenient for all compilers to be able to read and understand UNIX system file specifications.

The following file specification conversion functions are included in the Compaq C RTL to assist in porting C programs from UNIX systems to OpenVMS systems:

  • decc$match_wild
  • decc$translate_vms
  • decc$fix_time
  • decc$to_vms
  • decc$from_vms

Note

These DECC$ routine names replace the SHELL$ routine names previously available with the VAX C RTL.

The advantage of including these file specification conversion functions in the Compaq C RTL is that you do not have to rewrite C programs containing UNIX system file specifications. Compaq C can translate most valid UNIX system file specifications to OpenVMS file specifications.

Note

The Compaq C RTL cannot translate UNIX file specifications with more than one period character (.).

If the UNIX file specification contains a period, all slash characters (/) must precede that period.

Please note the differences between the UNIX system and OpenVMS file specifications, as well as the method used by the RTL to access files. For example, the RTL accepts a valid OpenVMS specification and most valid UNIX file specifications, but the RTL cannot accept a combination of both. Table 1-2 shows the differences between UNIX system and OpenVMS system file specification delimiters.

Table 1-2 UNIX and OpenVMS File Specification Delimiters
Description OpenVMS System UNIX System
Node delimiter :: !/
Device delimiter : /
Directory path delimiter [ ] /
Subdirectory delimiter [ . ] /
File extension delimiter . .
File version delimiter ; Not applicable

For example, Table 1-3 shows the formats of two valid specifications and one invalid specification.

Table 1-3 Valid and Invalid UNIX and OpenVMS File Specifications
System File Specification Valid/Invalid
OpenVMS BEATLE::DBA0:[MCCARTNEY]SONGS.LIS Valid
UNIX beatle!/usr1/mccartney/songs.lis Valid
     
--- BEATLE::DBA0:[MCCARTNEY.C]/songs.lis Invalid

When Compaq C translates file specifications, it looks for both OpenVMS and UNIX system file specifications. Consequently, there may be differences between how Compaq C translates UNIX system file specifications and how UNIX systems translate the same UNIX file specification.

For example, if the two methods of file specification are combined, as in Table 1-3, Compaq C RTL can interpret [MCCARTNEY.C]/songs.lis as either [MCCARTNEY]songs.lis or [C]songs.lis. Therefore, when Compaq C encounters a mixed file specification, an error occurs.

UNIX systems use the same delimiter for the device name, the directory names, and the file name. Due to the ambiguity of UNIX file specifications, Compaq C may not translate a valid UNIX system file specification according to your expectations.

For instance, the OpenVMS system equivalent of /bin/today can be either [BIN]TODAY or [BIN.TODAY]. Compaq C can make the correct interpretation only from the files present. If a file specification conforms to UNIX system file name syntax for a single file or directory, it is converted to the equivalent OpenVMS file name if one of the following conditions is true:

  • If the specification corresponds to an existing OpenVMS directory, it is converted to that directory name. For example, /dev/dir/sub is converted to DEV:[DIR.SUB] if DEV:[DIR.SUB] exists.
  • If the specification corresponds to an existing OpenVMS file name, it is converted to that file name. For example, /dev/dir/file is converted to DEV:[DIR]FILE if DEV:[DIR]FILE exists.
  • If the specification corresponds to a nonexistent OpenVMS file name, but the given device and directory exist, it is converted to a file name. For example, /dev/dir/file is converted to DEV:[DIR]FILE if DEV:[DIR] exists.

Note

Beginning with OpenVMS Version 7.3, you can instruct the Compaq C RTL to interpret the leading part of a UNIX-style file spec as either a subdirectory name or a device name.

As with previous releases, the default translation of foo/bar (UNIX-style name) is FOO:BAR (OpenVMS-style device name).

To request translation of foo/bar (UNIX-style name) to [.FOO]BAR (OpenVMS-style subdirectory name), define the logical name DECC$DISABLE_TO_VMS_LOGNAME_TRANSLATION to any value. DECC$DISABLE_TO_VMS_LOGNAME_TRANSLATION is checked only once per image activation, not on a file-by-file basis. Defining this logical affects not only the decc$to_vms function, but all Compaq C RTL functions that accept both UNIX-style and OpenVMS-style file names as an argument.

In the UNIX system environment, you reference files with a numeric file descriptor. Some file descriptors reference Standard I/O devices; some descriptors reference actual files. If the file descriptor belongs to an unopened file, the Compaq C RTL opens the file. Compaq C equates file descriptors with the following OpenVMS logical names:
File Descriptor OpenVMS Logical Meaning
0 SYS$INPUT Standard input
1 SYS$OUTPUT Standard output
2 SYS$ERROR Standard error

1.5 Feature-Test Macros for Header-File Control

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

The Compaq 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 Compaq 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 Compaq C RTL header files define symbols without restriction.

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

  • Standards
  • Multiple-version support
  • Compatibility

1.5.1 Standards Macros

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

  • X/Open CAE Specification, System Interfaces and Headers, Issue 4, Version 2, also known as XPG4 V2.
  • X/Open CAE Specification, System Interfaces and Headers, Issue 4, also known as XPG4.
  • 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.
  • ISO/IEC 9945-2:1993 - Information Technology - Portable Operating System Interface (POSIX) - Part 2: Shell and Utilities, also known as ISO POSIX-2.
  • 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.
  • ANSI/ISO/IEC 9899:1999 - The C99 standard, published by ISO in December, 1999 and adopted as an ANSI standard in April, 2000.
  • ISO/IEC 9899:1990-1994 - Programming Languages - C, Amendment 1: Integrity, also known as ISO C, Amendment 1.
  • 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.

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 Compaq C RTL feature-test macros that control standards support.

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

  • 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.
  • 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.
  • 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.
  • 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.
  • The fgetname function is a Compaq 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).
  • 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.
  • 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.

    So 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.
  • 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.


Previous Next Contents Index
Buy Online or Call 1.800.888.0220      privacy statement and legal notices 
STORES CONTACT US SEARCH PRODUCTS SOLUTIONS OPTIONS DEVELOPERS