United States    
COMPAQ STORE | PRODUCTS |
SERVICES | SUPPORT | CONTACT US | SEARCH
Compaq C

Compaq C
Migration Guide for OpenVMS VAX Systems


Previous Contents

2.3.2.2 The #pragma message Preprocessor Directive

The #pragma message directive controls the issuance of individual diagnostic messages or groups of messages. Use of this pragma overrides any command-line options that may affect the issuance of messages.

This pragma has the following format:

#pragma message option1 (message-list)
#pragma message option2

The parameter option1 must be one of the following keywords:

See the /WARNING qualifier ( Section 2.3.2.1) for a description of the message-list.

Only messages of severity Warning (W) or Information (I) can be disabled. If the message has severity of Error (E) or Fatal (F), it is issued regardless of any attempt to disable it.

The parameter option2 must be one of the following keywords:

The save and restore options are useful primarily within header files.

2.4 Using Compiler Modes and Message Control to Port your Program

The following steps describe a suggested path for porting your VAX C programs to the relaxed ANSI C mode of the Compaq C compiler.

  1. Use CC/DECC/STANDARD=VAXC, and then do the following:
    1. Make sure the code works.
    2. Consider making code changes on the basis of any diagnostic messages. You must change the code to eliminate E-level diagnostics.
    3. If you are not interested in using ANSI C modes, use #pragma message or /WARNINGS to suppress messages you do not want to see.
  2. Use CC/DECC/STANDARD=VAXC
    /WARNINGS=ENABLE=(PORTABLE,CHECK), and then do the following:
    1. Consider making code changes on the basis of any additional diagnostic messages. Some messages might point out language features that work differently between VAXC and ANSI C modes.
      Note that compiling this way just gives you more diagnostics; it does not change the behavior of your code.
    2. If you are not interested in using ANSI C modes, use #pragma message or /WARNINGS to suppress warning and informational messages you do not want to see.
  3. Use CC/DECC/STANDARD=RELAXED_ANSI, and then do the following:
    1. Consider making code changes on the basis of any additional diagnostic messages.
    2. Make sure the code works. There are language features that behave differently when compiling with /STANDARD=RELAXED_ANSI than when compiling with /STANDARD=VAXC.
    3. If you are not interested in using the strict ANSI C modes
      (/STANDARD=ANSI89 or /STANDARD=MIA), use #pragma message or /WARNINGS to suppress warning and informational messages you do not want to see.
      Stopping at /STANDARD=RELAXED_ANSI is recommended. It becomes increasingly difficult to compile in strict ANSI C mode.
  4. Use CC/DECC/STANDARD=ANSI89 or CC/DECC/STANDARD=MIA. This compiles in strict ANSI C mode. This step is not necessary for most OpenVMS users and is potentially undesirable.

2.5 New Mechanism for Controlling External Objects

The Compaq C compiler provides an alternative, ANSI-compliant method of controlling objects that have external linkage. To take advantage of this method, use the #pragma extern_model preprocessor directive and the /EXTERN_MODEL and /[NO]SHARE_GLOBALS command-line qualifiers.

The pragma and command-line qualifiers replace the VAX C mode storage-class specifiers ( globaldef , globalref , globalvalue ) and storage-class modifiers ( noshare and readonly ). They allow you to select the implementation model of external data and control the psect usage of your programs. The _align macro is still available to ensure object alignment.

For a description of #pragma extern_model and its relationship to the external storage classes it replaces, see the Preprocessor Directives chapter of the Compaq C User's Guide for OpenVMS Systems.

For a description of the command-line qualifiers /EXTERN_MODEL and /[NO]SHARE_GLOBALS, see the Developing C Programs at the DCL Command Level chapter of the Compaq C User's Guide for OpenVMS Systems.

For more information on external storage classes and psects, see the Data Storage chapter of the Compaq C User's Guide for OpenVMS Systems.

2.5.1 Extern Model Defaults Have Changed

This section explains how to use /EXTERN_MODEL=COMMON_BLOCK and /SHARE_GLOBALS to obtain the same extern model defaults as VAX C.

By default, VAX C uses the common block model for external objects and treats external objects as shared (that is, the psects created for external objects are marked as shared). In the common block model, all declarations are definitions, and the linker combines all definitions with the same name into one definition.

The Compaq C default for the initial extern model is different from that of VAX C, even when compiling in VAX C mode: Compaq C uses the relaxed refdef model and treats external objects as noshare. That is, the default qualifiers that govern the initial model for external objects are /EXTERN_MODEL=RELAXED_REFDEF and /NOSHARE_GLOBALS. In the relaxed refdef model, some declarations are references and some are definitions. Multiple uninitialized definitions for the same object are allowed and resolved into one by the linker. However, a reference requires that at least one definition exists. This model is used by C compilers on UNIX systems.

Note that the change in the extern model default from share to noshare could have the following impact:

For compatibility with VAX C, you may wish to change the Compaq C default extern model. To obtain the same extern model defaults as VAX C, use the following qualifiers:


$ CC/DECC/EXTERN_MODEL=COMMON_BLOCK/SHARE_GLOBALS

2.6 Mixing VAX C and Compaq C Object Files

You can mix object files compiled by the VAX C compiler and the Compaq C compiler. Because Compaq C does not support parallel processing, you might want to mix object files as a workaround for parallel processing usage in your VAX C programs.

To mix object files:

  1. Separately compile the VAX C code and the Compaq C code:


    $ CC/DECC PROG1
    $ CC/VAXC PROG2
    

  2. Link the object modules together and with the Compaq C RTL:

See Section 1.2 for more information on linking with the Compaq C RTL.

2.7 Using Predefined Macros to Aid Coexistence of VAX C and Compaq C code

This section describes how to use predefined system-identification macros to aid in the coexistence of VAX C and Compaq C code.

Each implementation of the Compaq C compiler automatically defines macros that you can use to identify the system on which the program is running. These macros can assist in writing code that executes conditionally, depending on the architecture or operating system on which the program is running, and on the compiler and/or qualifiers specified.

See the Predefined Macros and Builtin Functions chapter of the Compaq C User's Guide for OpenVMS Systems for a list of the traditional (non-ANSI) and new (ANSI) spellings of these predefined macro names for Compaq C for OpenVMS Systems.

The predefined macro symbols are defined as 1 or 0, as appropriate to the compiler, processor, and compilation qualifiers.

The __DECC Macro

For the purposes of this discussion, we are interested in the __decc predefined macro. The Compaq C compiler always defines __decc to be 1; it is not defined for the VAX C compiler. You can use this fact to separate VAX C code from Compaq C code, as in the following example:


#ifdef    __DECC 
#pragma extern_model common_block shr 
#endif 

In this example, if the code is being compiled by Compaq C, the default model for external variables is changed from relaxed_refdef noshr (the Compaq C default) to common_block shr (the VAX C default). See Section 2.5 for more information about #pragma extern_model .

Do not use the __vaxc predefined macro to try to distinguish between the two compilers because __vaxc is defined to be 1 both by the VAX C compiler and by the Compaq C compiler in VAX C mode.

The __alpha and __Alpha_AXP Macros

Several other predefined macros are available with Compaq C. For example, a program can use __alpha and __alpha_axp to perform processor-specific functions on Alpha systems. For example:


#ifdef    __alpha 
void __PAL_BPT (void); 
#endif 

The __HIDE_FORBIDDEN_NAMES Macro

You might also find the __hide_forbidden_names macro useful.

The ANSI C standard specifies exactly what identifiers in the normal name space are declared by the standard header files. A compiler is not free to declare additional identifiers in a header file unless the identifiers follow defined rules (the identifier must begin with an underscore followed by an uppercase letter or another underscore).

When running the Compaq C compiler for OpenVMS systems in strict ANSI C mode (/STANDARD=ANSI89), versions of the standard header files are included that hide many identifiers that do not follow the rules. The header file <stdio.h> , for example, hides the definition of the macro TRUE. The compiler accomplishes this by predefining the macro __hide_forbidden_names in strict ANSI C mode.

You can use the command-line qualifier /UNDEFINE="__HIDE_FORBIDDEN_NAMES" to prevent the compiler from predefining this macro and, thereby, including macro definitions of the forbidden names.

The header files are modified to only define additional VAX C names if __hide_forbidden_names is undefined. For example, <stdio.h> might contain the following:


#ifndef __HIDE_FORBIDDEN_NAMES 
#define TRUE    1 
#endif 

2.8 Additional Information

For additional information on Compaq C features, see the Compaq C User's Guide for OpenVMS Systems. This guide contains a New and Changed Features appendix that you might find useful. This appendix summarizes the features that distinguish Compaq C for OpenVMS Systems from VAX C Version 3.2. You might also want to read the Common Pitfalls appendix of the user's guide.

Previous Contents Contents
  

1.800.AT.COMPAQ

privacy and legal statement