United States

Compaq C

# Compaq C
Run-Time Library Reference Manual for OpenVMS Systems

Previous | Contents | Index

## 1.3.2 Resolving Link-Time Conflicts with Multiple C RTLs

This section describes the use of interoperability tools to resolve link-time conflicts when using multiple C RTLs.

When migrating to the Compaq C RTL, multiple C RTLs will likely be needed to link an application. One C RTL might be explicitly linked against. A second C RTL might not be explicitly linked against, but brought into the link by means of a shareable image. For example, when developing a Motif program using Compaq C, the application must be linked against the Compaq C RTL and against the Motif images. Motif currently brings the VAX C RTL into the link.

Problems encountered when linking with multiple C RTLs are a result of the OpenVMS linker resolving symbol references in the image being linked by searching the transitive closure of shareable images and libraries. That is, when linking with a shareable image, the linker searches that shareable image and all shareable images referenced in that shareable image. So when linking with VAXCRTL.EXE and with an image linked with VAXCRTLG.EXE, the linker will find two instances of all the C RTL symbols (one in VAXCRTL and one in VAXCRTLG), and report a conflict.

The object libraries do not conflict with routine names, but do conflict with the global symbols. Because VAX C implements global symbols as global overlaid psects, the linker attempts to connect all the instances of a C-generated psect with the same name. For example, a reference to `stdin` in the user program is connected with the psect of the same name in VAXCRTL.OLB. However, a shareable image that was linked with VAXCRTL.OLB also has a psect of the same name; this results in an error because the linker cannot connect those two definitions of the psect `stdin` .

Three interoperability tools are provided with the Compaq C compiler and in a separate Compaq C/C++ RTL Run-Time Components kit to resolve link-time conflicts:

- VAXC$LCL.OPT
- VAXC$EMPTY.EXE
- DECC$EMPTY.EXE

These tools work by hiding the conflicting symbols from one of the C RTLs being linked. Which tool is required depends on what C RTLs are used by the main application and the shareable image.

Table 1-1 shows typical C RTL conflicts and the interoperability tool required to resolve it. In the table, VAXCRTL.EXE refers to either VAXCRTL.EXE or VAXCRTLG.EXE.

Table 1-1 Linking Conflicts
Linker Message | Type of Conflict | Tool Needed
--- | --- | ---
LINK-E-MULSHRPSC | VAXCRTL.OLB/VAXCRTL.EXE | VAXC$LCL.OPT
LINK-E-SHRPSCLNG | VAXCRTL.OLB/DECCRTL.OLB | VAXC$LCL.OPT
LINK-E-MULSHRPSC, LINK-E-SHRPSCLNG | DECCRTL.OLB/VAXCRTL.EXE | VAXC$LCL.OPT
None. | DECCRTL.OLB/DECC$SHR.EXE | DECC$EMPTY
LINK-W-MULDEF | VAXCRTL.EXE/VAXCRTLG.EXE | VAXC$EMPTY
LINK-W-MULDEF | VAXC2DECC.EXE/VAXCRTL.EXE | VAXC$EMPTY

### 1.3.2.1 Using VAXC$LCL.OPT

VAXC$LCL.OPT is required when building any shareable image linked with the VAX C RTL object library or Compaq C RTL object library.

If the shareable image is built without using VAXC$LCL.OPT, the C RTL global symbols are visible in the shareable image and cause linker conflicts when users of the image link against it. For example:

    %LINK-E-MULSHRPSC, psect C$$TRNS_VALUES defined in
            shareable image IMAGE1.EXE; is multiply defined in
            shareable image SYS$LIBRARY:VAXCRTL.EXE;1
    -LINK-E-NOIMGFIL, image file not created

In this example, the shareable image IMAGE1 uses VAXCRTL.OLB, and the image being linked uses VAXCRTL.EXE. For a successful link, relink the shareable image using VAXC$LCL.OPT:

    $ LINK/SHARE IMAGE1.OBJ, IMAGE1.OPT/OPTIONS, SYS$LIBRARY:VAXCRTL/LIBRARY, - _$ SYS$LIBRARY:VAXC$LCL.OPT/OPTIONS

The following message also indicates a conflict involving the VAX C RTL object library:

    %LINK-E-SHRPSCLNG, Psect STDIN has length of 8
            in module C$EXTERNDATA file SYS$LIBRARY:DECCRTL.OLB;2
            which exceeds length of 4 in shareable image IMAGE1.EXE;
    -LINK-E-NOIMGFIL, image file not created

In this example, the shareable image IMAGE1 uses VAXCRTL.OLB, and the image being linked uses DECCRTL.OLB. For a successful link, relink the shareable image using VAXC$LCL.OPT.

If the shareable image cannot be relinked (as in the case of a third-party shareable image), then the interoperability tool can be applied to the main image. If the main image is being linked against DECCRTL.OLB, then apply VAXC$LCL.OPT to the link of the main image.

If the main image is being linked against VAXCRTL.EXE, the only solution is to get the shareable image fixed, because applying any of the interoperability tools to the link of the main image will result in an unsuccessful link.

### 1.3.2.2 Using VAXC$EMPTY.EXE

Use VAXC$EMPTY.EXE to link a main application with both VAXC2DECC.EXE (or VAXCG2DECC.EXE) and a shareable image linked with VAXCRTL.EXE (or VAXCRTLG.EXE). Using VAXC$EMPTY.EXE hides all the global symbols in the VAXCRTL*.EXE shareable image to prevent conflicts with VAXC2DECC.EXE or VAXCG2DECC.EXE.

Also use VAXC$EMPTY.EXE to link an application with both VAXCRTL.EXE and a shareable image linked with VAXCRTLG.EXE (or vice versa).

When there is a conflict between C RTL shareable images, the linker produces large numbers of messages similar to the following:

    %LINK-W-MULDEF, symbol ACOS multiply defined
            in module VAXCRTL file SYS$COMMON:[SYSLIB]VAXCRTL.EXE;18

In this example, the shareable image is linked with VAXCRTL.EXE, and the main program is linked with VAXC2DECC.EXE.

The solution is to define the VAXCRTL logical to point to VAXC$EMPTY.EXE before linking the main program:

    $ DEFINE/USER VAXCRTL SYS$LIBRARY:VAXC$EMPTY.EXE
    $ LINK/EXEC=MAIN_IMAGE MAIN_PROG,OBJ1,OBJ2,...,SYS$INPUT:/OPTIONS
    IMAGE1/SHARE
    VAXCRTL/SHARE
    [Ctrl/Z]

Note the following about this solution:

- Your linker options file cannot reference SYS$LIBRARY:VAXCRTL; it must reference only VAXCRTL.
- Do not link explicitly against VAXC$EMPTY.EXE, or your application will neither link nor run correctly.
- Do not leave the VAXCRTL pointing to VAXC$EMPTY.EXE, or your application will not run correctly.
- The DEFINE/USER command is used to ensure that the logical definition is removed after execution of the LINK command. Make sure that no commands intervene between the DEFINE/USER command and the LINK command.

Follow the same process when linking against VAXCRTLG.EXE by defining the VAXCRTLG logical to point to VAXC$EMPTY.EXE.

### 1.3.2.3 Using DECC$EMPTY.EXE

The DECC$EMPTY.EXE interoperability tool allows a program to use the Compaq C object library even when the program links with a shareable image that was linked with DECC$SHR.EXE.

If DECC$EMPTY.EXE is not used during the link, all Compaq C RTL references from the main program will be resolved in DECC$SHR.EXE, not in the object library. There is no linker message that indicates this fact.

For example, if IMAGE1 is linked against DECC$SHR, and the following link is performed, then the main image will not contain any Compaq C RTL object modules. All C RTL references from the main progam are resolved in DECC$SHR:

    $ LINK/EXEC=MAIN_IMAGE MAIN_PROG,OBJ1,...,SYS$INPUT:/OPTIONS
    IMAGE1/SHARE
    SYS$LIBRARY:DECCRTL/LIBRARY
    [Ctrl/Z]

By defining the DECC$SHR logical to point to DECC$EMPTY.EXE immediately before the link, all references to C RTL symbols from the main program are resolved in the Compaq C RTL object library. For example:

    $ DEFINE/USER DECC$SHR SYS$LIBRARY:DECC$EMPTY.EXE
    $ LINK/EXEC=MAIN_IMAGE MAIN_PROG,OBJ1,...,SYS$INPUT:/OPTIONS
    IMAGE1/SHARE
    SYS$LIBRARY:DECCRTL/LIBRARY

Note the following about this solution:

- Do not link explicitly against DECC$EMPTY.EXE, or your application will neither link correctly nor run correctly.
- Do not leave the DECC$SHR logical pointing to DECC$EMPTY.EXE, or your application will not run correctly.
- The DEFINE/USER command is used to ensure that the logical definition is removed after execution of the LINK command. Make sure that no commands intervene between the DEFINE/USER command and the LINK command.

## 1.3.3 Linking Examples for Compaq C or Compaq C++ Code Only

The following examples show the different ways you might want to link Compaq C only or Compaq C++ only programs with the Compaq C RTL on OpenVMS VAX systems:

1. Most of the time, you just want to link against the shareable image:

       $ CC/DECC/PREFIX_LIBRARY_ENTRIES=ALL_ENTRIES PROG1
       $ LINK PROG1

   The linker automatically searches IMAGELIB.OLB to find DECC$SHR.EXE.
2. If you want to use just object libraries (to write privileged code or for ease of distribution, for example), use the /NOSYSSHR qualifier of the LINK command:

       $ CC/DECC/PREFIX_LIBRARY_ENTRIES=ALL_ENTRIES PROG1
       $ LINK/NOSYSSHR PROG1, SYS$LIBRARY:DECCRTL.OLB/LIBRARY/INCL=CMA$TIS

       $ LINK/NOSYSSHR PROG1, -
       _$ SYS$LIBRARY:DECCRTL.OLB/LIBRARY/INCL=(CMA$TIS,CMA$TIS_VEC) (OPENVMS V7.3 AND HIGHER)

   Prefixed Compaq C RTL symbol references in the user program are resolved in STARLET.OLB.
3. When compiling with prefixing disabled, in order to use object libraries that provide alternate implementations of C RTL functions, you need to use the DECC*.OLB object libraries. In this case, compile and link as follows:

       $ CC/DECC/NOPREFIX_LIBRARY_ENTRIES PROG1
       $ LINK PROG1, MYLIB/LIBRARY, -
       _$ SYS$LIBRARY:DECCRTL.OLB/LIBRARY

   Unprefixed Compaq C RTL symbol references in the user program are resolved in MYLIB and DECCRTL.OLB. The unprefixed names refrence prefixed names resolved in DECC$SHR.EXE.
   You can link with any valid combination of DECCRTL.OLB, DECCRTLG.OLB, and DECCCURSE.OLB. In this same example, to get G-floating double-precision, floating-point support, you might use the following compile and LINK commands:

       $ CC/DECC/NOPREFIX_LIBRARY_ENTRIES/FLOAT=G_FLOAT PROG1
       $ LINK PROG1, MYLIB/LIBRARY, SYS$LIBRARY:DECCRTLG.OLB/LIBRARY, -
       _$ SYS$LIBRARY:DECCRTL.OLB/LIBRARY

4. Combining examples 2 and 3, you might want to use just the object libraries (for writing privileged code or for ease of distribution) and use an object library that provides C RTL functions. In this case, compile and link as follows:

       $ CC/DECC/NOPREFIX_LIBRARY_ENTRIES PROG1
       $ LINK/NOSYSSHR PROG1, MYLIB/LIBRARY, -
       _$ SYS$LIBRARY:DECCRTL.OLB/LIBRARY

## 1.3.4 Linking Examples for VAX C and Compaq C Code Combined

You might have programs that combine VAX C and Compaq C (or Compaq C++) code. The following examples show different ways to link such programs with the Compaq C RTL on OpenVMS VAX systems. These examples correspond to the examples in Section 1.3.3.

1. To link against the shareable image, specify the VAXC2DECC.EXE shareable image:

       $ CC/DECC PROG1
       $ CC/VAXC PROG2
       $ LINK PROG1, PROG2, TT:/OPTIONS
       SYS$LIBRARY:VAXC2DECC.EXE/SHARE
       [Ctrl/Z]

   Prefixed C RTL calls from PROG1 are resolved in DECC$SHR. Unprefixed C RTL calls from PROG2 are resolved in VAXC2DECC.EXE, which transfers them to DECC$SHR.
2. If you want to use just object libraries (to write privileged code or for ease of distribution, for example), use the /NOSYSSHR qualifier of the LINK command:

       $ CC/DECC PROG1
       $ CC/VAXC PROG2
       $ LINK/NOSYSSHR PROG1, PROG2, SYS$LIBRARY:DECCRTL.OLB/LIBRARY/INCL=CMA$TIS

   All C RTL calls from both PROG1 and PROG2 are resolved in DECCRTL.OLB.
3. When compiling with prefixing disabled, in order to use object libraries that provide alternate implementations of C RTL functions, you need to use the DECC*.OLB object libraries. In this case, compile and link as follows:

       $ CC/DECC/NOPREFIX_LIBRARY_ENTRIES PROG1
       $ CC/VAXC PROG2
       $ LINK PROG1, PROG2, MYLIB/LIBRARY, -
       _$SYS$LIBRARY:DECCRTL.OLB/LIBRARY/INCL=CMA$TIS

   Unprefixed Compaq C RTL symbol references in the user program are resolved in MYLIB and DECCRTL.OLB.
4. Combining examples 2 and 3, you might want to use just the object libraries (for writing privileged code or for ease of distribution) and use an object library that provides C RTL functions. In this case, compile and link as follows:

       $ CC/DECC/NOPREFIX_LIBRARY_ENTRIES PROG1
       $ CC/VAXC PROG2
       $ LINK/NOSYSSHR PROG1, PROG2, MYLIB/LIBRARY, -
       _$ SYS$LIBRARY:DECCRTL.OLB/LIBRARY /INCL=CMA$TIS

## 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` . This prototype indicates the arguments and the return value of `feof` .
- 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

Previous | Next | Contents | Index

privacy and legal statement