DEC C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index


Chapter 1
Introduction

The ISO/ANSI C standard defines a library of functions, as well as related types and macros, to be provided with any implementation of ANSI C. The DEC C Language Reference Manual describes the ANSI-conformant library features common to all DEC C platforms. The DEC C Run-Time Library Reference Manual for OpenVMS Systems provides a more detailed description of these routines and their use in the OpenVMS environment. It also documents additional header files, functions, types, and macros that are available on the OpenVMS system.

All library functions are declared in a header file. To make the contents of a header file available to your program, include the header file with an #include preprocessor directive. For example:


#include <stdlib.h> 

Each header file contains function prototypes for a set of related functions, and defines any types and macros needed for their use.

To list the header files on OpenVMS Alpha systems, use the following commands:


$ LIBRARY/LIST ALPHA$LIBRARY:SYS$STARLET_C.TLB
  (ALPHA ONLY)
 
$ LIBRARY/LIST ALPHA$LIBRARY:DECC$RTLDEF.TLB
  (ALPHA ONLY)
 
$ DIR SYS$COMMON:[DECC$LIB.REFERENCE.DECC$RTLDEF]*.H;
  (ALPHA ONLY)
 
$ DIR ALPHA$LIBRARY:*.H; 
  (ALPHA ONLY)

The first command lists the text module form of the header files for the OpenVMS system interfaces. The second lists the text module form of the header files for the DEC C language interface. The third lists *.h header files for the DEC C language interfaces. The fourth lists *.h header files for layered products and other applications.

Note

The SYS$COMMON:[DECC$LIB.REFERENCE.DECC$RTLDEF] directory is only a reference area for your viewing. The compiler still looks in the *.TLB files for #include file searches.

To list the header files on OpenVMS VAX systems, use one of the following command:


$ DIR 'F$TRNLMN("DECC$LIBRARY_INCLUDE")'*.H;  (VAX ONLY)
$ DIR DECC$LIBRARY_INCLUDE:*.H;  (VAX ONLY)

On OpenVMS VAX systems, the following command might also find additional or duplicate header files:


$ DIR SYS$LIBRARY:*.H;  (VAX ONLY)

However, duplicate files (such as <stdio.h> ) found in SYS$LIBRARY probably support the VAX C Version 3.2 environment and should not be used with DEC C.

Function definitions themselves are not included in the header files, but are contained in the DEC C Run-Time Library (RTL) shipped with the OpenVMS operating system. Before using the DEC C RTL, you must be familiar with the following topics:

A knowledge of all these topics is necessary to effectively use the DEC C RTL. This chapter shows the connections between these topics and the DEC C RTL. Read this chapter before any of the other chapters in this manual.

The primary purpose of the DEC C RTL is to provide a means for C programs to perform I/O operations; the C language itself has no facilities for reading and writing information. In addition to I/O support, the DEC C RTL also provides a means to perform many other tasks.

Chapters 2 through 11 describe the various tasks supported by the DEC C RTL. The Reference Section alphabetically lists and describes all the functions and macros available to perform these tasks.

1.1 Using the DEC C Run-Time Library

When working with the DEC C RTL, you must be aware of some implementation specifics.

First, if you plan to use DEC C RTL functions in your C programs, make sure that a function named main or a function that uses the main_program option exists in your program. For more information, see the DEC C Language Reference Manual or the DEC C User's Guide for OpenVMS Systems.

Second, the DEC C RTL functions are executed at run time, but references to these functions are resolved at link time. When you link your program, the OpenVMS Linker resolves all references to DEC C RTL functions by searching any shareable code libraries or object code libraries specified on the LINK command line.

You can use the DEC C RTL as a shareable image or you can use the DEC C RTL object libraries.

When you use the DEC C RTL as a shareable image, the code for the RTL resides in an image file in SYS$SHARE and is shared by all DEC C programs. After execution, control returns to your program. This process has a number of advantages:

When linking to the DEC C RTL, you do not need to define any LNK$LIBRARY logicals. In fact, you should deassign LNK$LIBRARY because linking with the shareable image is more convenient than linking with the DEC C RTL object libraries.

See your OpenVMS, DEC C, or DEC C++ release notes for any supplemental information about linking with the DEC C RTL.

1.2 RTL Linking Options on Alpha Systems (ALPHA ONLY)

The following sections describe several ways of linking DEC C and DEC C++ programs with the DEC C RTL on OpenVMS Alpha systems.

1.2.1 Linking with the Shareable Image

Most linking needs should be satisfied by using the DEC C RTL shareable image DECC$SHR.EXE in the ALPHA$LIBRARY directory.

The shareable images VAXCRTL.EXE and VAXCRTLG.EXE do not exist on OpenVMS Alpha systems. The only C RTL shareable image is ALPHA$LIBRARY:DECC$SHR.EXE, which the linker automatically finds through IMAGELIB.OLB.

The fact that VAXCRTL*.EXE does not exist on Alpha systems has the following ramifications:

To link against the shareable image, use the LINK command. For example:


$ LINK PROG1

The linker automatically searches IMAGELIB.OLB to find DECC$SHR.EXE, and resolves all C RTL references.

1.2.2 Linking with the Object Libraries

The DEC C RTL object libraries are used solely for linking programs compiled without /PREFIX=ALL.

On OpenVMS Alpha systems, the DEC C RTL provides the following object libraries in the ALPHA$LIBRARY directory:

The object library VAXCCURSE.OLB, which provides access to the curses functions, contains unprefixed entry points that vector to the appropriate prefixed entry points.

The object libraries VAXCRTL.OLB, VAXCRTLD.OLB, VAXCRTLT.OLB, VAXCRTLX.OLB, VAXCRTLDX.OLB, and VAXCRTLTX.OLB also contain unprefixed entry points that vector to the appropriate prefixed entry points, depending on the floating-point type specified by the object library used:

/L_DOUBLE_SIZE=128 is the default.

On the LINK command, specify only one of the VAXCRTL*.OLB libraries and, if needed, the VAXCCURSE.OLB library.

In the default mode of the compiler (/STANDARD=RELAXED_ANSI89) and also in strict ANSI C mode, all calls to ANSI C standard library routines are automatically prefixed with DECC$. With the /[NO]PREFIX_LIBRARY_ENTRIES qualifier, you can change this to prefix all DEC C RTL names with DECC$, or to not prefix any DEC C RTL names. Other options are also available for this qualifer. See the /[NO]PREFIX_LIBRARY_ENTRIES qualifier in this chapter for more information.

When linking with /NOSYSSHR, if calls to the DEC C RTL routines are prefixed with DECC$, then the modules in STARLET.OLB are the only ones you need to link against. Since STARLET.OLB is automatically searched by the linker (unless the link qualifier /NOSYSLIB is used), all prefixed RTL external names are automatically resolved.

If any calls to the DEC C RTL routines are not prefixed, then you need to explicitly link against VAXCRTL.OLB, VAXCRTLD.OLB, VAXCRTLT.OLB (or VAXCRTLX.OLB, VAXCRTLDX.OLB, or VAXCRTLDX.OLB), or VAXCCURSE.OLB, depending on which floating-point types you need, or if you want curses functions. If you are linking with /NOSYSSHR, prefixed DEC C RTL entry points are resolved in STARLET.OLB. If you are linking with /SYSSHR (the default), prefixed DEC C RTL entry points are resolved in DECC$SHR.EXE.

1.2.3 Examples

The following examples show several different ways you might want to link with the DEC C RTL. See Figure 1-1 for a graphical summary of these examples.

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


    $ CC/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/PREFIX_LIBRARY_ENTRIES=ALL_ENTRIES PROG1
    $ LINK/NOSYSSHR PROG1
    

    Prefixed RTL symbol references in the user program are resolved in the DEC C RTL object library contained 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 VAXC*.OLB object libraries. In this case, compile and link as follows:


    $ CC/NOPREFIX_LIBRARY_ENTRIES PROG1
    $ LINK PROG1, MYLIB/LIBRARY, ALPHA$LIBRARY:VAXCRTLX.OLB/LIBRARY
    

    Unprefixed DEC C RTL symbol references in the user program are resolved in MYLIB and in VAXCRTL.OLB.
    Prefixed DEC C RTL symbol references in VAXCRTLX.OLB are resolved in DECC$SHR.EXE through IMAGELIB.OLB.
    In this same example, to get IEEE T-floating double-precision floating-point support, you might use the following compile and link commands:


    $ CC/NOPREFIX_LIBRARY_ENTRIES/FLOAT=IEEE_FLOAT PROG1
    $ LINK PROG1, MYLIB/LIBRARY, ALPHA$LIBRARY:VAXCRTLTX.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/NOPREFIX_LIBRARY_ENTRIES PROG1
    $ LINK/NOSYSSHR PROG1, MYLIB/LIBRARY, ALPHA$LIBRARY:VAXCRTLX.OLB/LIBRARY
    

    Prefixed DEC C RTL symbol references in VAXCRTL.OLB are resolved in STARLET.OLB.

Figure 1-1 Linking with the DEC C RTL on OpenVMS Alpha Systems


1.3 RTL Linking Options on VAX Systems (VAX ONLY)

Both the VAX C RTL and the DEC C RTL can coexist on your OpenVMS VAX system. The VAX C RTL supports existing VAX C applications. The DEC C RTL supports ANSI-compliant DEC C and DEC C++, as well as other components of the OpenVMS environment. The DEC C RTL also provides a mechanism for thread safety and performance improvements.

Applications developed with VAX C will continue to use the VAX C RTL. However, you can relink VAX C applications to use the DEC C RTL instead. This lets you take advantage of the new features of the DEC C RTL and solve potential interoperability problems in complex applications that incorporate both the VAX C RTL and the DEC C RTL. Existing applications that are relinked to use the DEC C RTL should be carefully tested for possible problems resulting from the differences in behavior between the VAX C RTL and the DEC C RTL. See the applicable DEC C release notes and OpenVMS release notes for more information.

The following sections describe several ways of linking DEC C programs with the DEC C RTL and VAX C RTL on OpenVMS VAX systems.

1.3.1 Linking with the DEC C RTL

The DEC C RTL provides a new set of files with different names from the VAX C RTL files. If you want to link with the DEC C RTL, you need to change your link procedures to use the new file names. The following sections describe linking with the DEC C RTL files.

1.3.1.1 Linking with the DEC C RTL Shareable Images

Most linking needs should be satisfied by using the DEC C RTL shareable image DECC$SHR.EXE in the SYS$LIBRARY directory. Use this linking method for programs that are written entirely in DEC C or DEC C++ code; that is, with no VAX C object modules.

Because DECC$SHR.EXE exports only prefixed universal symbols (ones that begin with DECC$), to successfully link against it make sure you cause prefixing to occur for all DEC C RTL entry points.

If you use only the DEC C RTL functions defined in the ANSI C Standard, all entry points will be prefixed.

If you use DEC C RTL functions not defined in the ANSI C Standard, you must compile in one of two ways to ensure prefixing:

Then link against the shareable image using the LINK command. For example:


$ LINK PROG1

If you are using the VAX C compiler and you want to link with DECC$SHR.EXE, you must link to one of the following files:

You link with them as follows:


$ LINK PROG1,TT:/OPTIONS
SYS$LIBRARY:VAXC2DECC/SHARE
[Ctrl/Z]

Use the G-floating version, VAXCG2DECC.EXE, if you compiled with the /G_FLOAT or /FLOAT=G_FLOAT qualifier.

1.3.1.2 Linking with or Providing Your Own Shareable Images

Most linking needs for an application using a shareable image are handled by a straight forward link command, regardless of whether the shared image uses DEC C, VAX C or some other programming language.

For example, assume that SHARE1.EXE is a shareable image linked with VAXCRTL.EXE. Also assume that your program, PROG1, is compiled with DEC C and, therefore, references prefixed names for C RTL functions. You can then use the following commands:


$ LINK PROG1, SYS$INPUT:/OPTIONS 
MYDISK:[TEXT]SHARE1.EXE/SHARE 

If PROG1 does not use prefixed names, the link could result in link conflicts. If this occurs, see Section 1.3.2.

1.3.1.3 Linking with the DEC C RTL Object Libraries

The DEC C RTL object libraries are used primarily for linking with the /NOSYSSHR qualifier.

On OpenVMS VAX systems, the DEC C RTL provides the following object libraries in the SYS$LIBRARY directory:

As with VAX C, if you specify more than one object library on the LINK command, you must do so in the order listed.

You use these object libraries in the same way that you would use the VAX C RTL object libraries VAXCRTL.OLB, VAXCRTLG.OLB, and VAXCCURSE.OLB. For example:


$ ! Link a D-float program
$ LINK PROG1, SYS$LIBRARY:DECCRTL.OLB/LIBRARY
$ !
$ ! Link a G-float program
$ LINK PROG2, SYS$LIBRARY:DECCRTLG.OLB/LIBRARY, - 
_$ SYS$LIBRARY:DECCRTL.OLB/LIBRARY
$ !
$ ! Link a D-float, curses program
$ LINK PROG1, SYS$LIBRARY:DECCCURSE.OLB/LIBRARY, - 
_$ SYS$LIBRARY:DECCRTL.OLB/LIBRARY

Note

When linking to the DEC C RTL object libraries, you do not need to define any LNK$LIBRARY logicals. In fact, you must deassign LNK$LIBRARY when linking with the .OLB libraries; otherwise, you might see "multiply defined symbols" errors.

In general, you should deassign LNK$LIBRARY because pointing this logical to the DEC C RTL object libraries interferes with VAX C development.

1.3.1.4 Linking with the DEC C RTL Object Libraries /NOSYSSHR

If you want to link your program with the DEC 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 DEC C RTL. You must use a linker options file or list the DEC C RTL object library on the command line. For example:


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

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 DEC 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 DEC C, the application must be linked against the DEC 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 DEC C compiler and in a separate DEC C/C++ RTL Run-Time Components kit to resolve link-time conflicts:

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


Previous Next Contents Index