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

Compaq C
User's Guide for OpenVMS Systems


Previous Contents Index

A.1.30.1 White Space Appearing Before the #

The ANSI C Standard removes the VAX C restriction that requires the # character introducing a preprocessor directive to always appear in column 1 of the source line. In Compaq C, white space and comments can now precede the # on the same line.

A.1.30.2 The #define Directive and Macro Substitution

Before the ANSI C Standard, the lack of a precise definition of the behavior of macro expansion led to a number of inconsistencies among different C implementations. Compaq C, in adhering to the ANSI C Standard, removes these and many other discrepancies by specifying precisely how macro substitution is to be performed:

  • Except when running in VAX C or common mode, macro arguments are not allowed to replace parameters appearing within character strings in the macro definition.
  • Except when running in VAX C or common mode, tokens within a macro definition are not concatenated if they were separated only by a comment; embedded comments are replaced by a blank.
  • In all modes, keywords are allowed to be defined as macros.
  • Macros are not replaced recursively in any mode except VAX C mode.

As required by the ANSI C Standard, Compaq C supports two new operators that can appear only within macro definitions:

  • The # operator takes a macro parameter as its operand and creates a character string from it. Combined with the new rule that adjacent character strings are implicitly concatenated into a single string, this provides the same capability as allowing substitution within strings.
  • The ## operator concatenates the tokens on either side of it into a single token.

The ANSI C Standard also makes specific the sequence in which rescanning and further substitution is to take place, and under what conditions substitution does not take place. The ANSI C Standard also specifies under what circumstances a macro may be redefined: only benign redefinition is allowed, permitting a macro to be redefined only if the new definition is token-wise identical to the old definition.

A.1.30.3 The #line Directive

The ANSI C Standard specifies that macro substitution can occur on the operands of the #line directive, that the line number operand is restricted to the range 1 to 32,767, and that the file name operand must be treated as any character string literal. VAX C did not support macro substitution on this directive, performed no range checking on the line number, and restricted the length of the character string to 255.

Compaq C supports macro substitution on the #line directive, diagnoses an out-of-range line number (in strict ANSI C mode only), and allows the file name character string to be as long as the maximum length supported by the compiler for ordinary strings. (Note that the ANSI C Standard requires support for a minimum of 509 characters in a string, and that Compaq C supports strings up to 65,535 characters.)

A.1.30.4 The #error Directive

Compaq C in both strict ANSI C mode and VAX C mode supports the new #error directive required by the ANSI C Standard.

A.1.30.5 The #pragma builtins Directive

The #pragma builtins directive is provided for VAX C compatibility.

Compaq C implements #pragma builtins by including the <builtins.h> header file, and is equivalent to #include <builtins.h> on OpenVMS systems.

This header file contains prototype declarations for the built-in functions that allow them to be used properly. By contrast, VAX C implemented this pragma with special-case code within the compiler, which also supported a #pragma nobuiltins preprocessor directive to turn off the special processing. Because declarations cannot be "undeclared," Compaq C does not support #pragma nobuiltins . Furthermore, the names of all the built-in functions use a naming convention defined by ANSI C to be in a namespace reserved to the C language implementation.

A.1.30.6 The #pragma dictionary Directive

The #pragma dictionary preprocessor directive replaces the #dictionary directive, but the latter is still supported in VAX C mode for compatibility.

The #pragma dictionary and #dictionary preprocessor directives now allow you to specify whether all string data type variables should be null-terminated.

A.1.30.7 The #pragma extern_model Directive

The #pragma extern_model directive is added to control the compiler's interpretation of objects that have external linkage. This pragma lets you choose the global symbol model to be used for external variables.

A.1.30.8 The #pragma linkage Directive (ALPHA ONLY)

The #pragma linkage preprocessor directive allows you to specify special linkage types for function calls.

A.1.30.9 The #pragma use_linkage Directive (ALPHA ONLY)

The #pragma use_linkage directive associates a previously defined special linkage with a function.

A.1.30.10 The #pragma message 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.

A.1.30.11 The #pragma module Directive

The #pragma module preprocessor directive replaces the #module directive, but the latter is still supported in VAX C mode for compatibility.

A.2 Features Affecting the Compaq C Run-Time Library and Include Files

This section describes new features pertaining to the standard header files in the Compaq C Run-Time Library (RTL).

A.2.1 <stddef.h>

The wchar_t type is now added to this header file. The declaration of errno is also removed.

A.2.2 <ctype.h>

Because the ANSI C Standard refers to the macros in <ctype.h> as functions, the <ctype.h> header file now includes function prototypes for functions in the Compaq C RTL that perform the same operations as the macros currently defined in this header file. These functions have been added to the Compaq C RTL.

The nonstandard toascii macro remains because, according to the ANSI C Standard, Section 4.14.2, names beginning with "to" are reserved by the ANSI C Standard when <ctype.h> is included.

A.2.3 <fp_class.h>

This header file containing IEEE floating-point class constants has been added to support the new Compaq C RTL functions fp_class , fp_classf , and fp_classl available on OpenVMS Alpha systems.

A.2.4 <locale.h>

The new standard header file <locale.h> is now supported and includes prototypes for the functions setlocale and localeconv , which have been added to the Compaq C RTL.

A.2.5 <math.h>

The functions cabs and hypot are no longer defined in the <math.h> header file when the compiler is run in strict ANSI C mode.

A.2.6 <signal.h>

The SIGABRT signal is implemented and defined in the <signal.h> header file. SIG_ATOMIC_T is now defined as char . In strict ANSI C mode, the following are not declared: ssignal , gsignal , kill , pause , sleep , sigvec , sigblock , sigsetmask , sigstack , and sigpause .

In strict ANSI C mode, the names of the ILL_* and FPE_* macros are changed to begin with " SIG " (for example, SIGILL_RESAD_FAULT , SIGFPE_INTOVF_TRAP , and so on) or be removed.

The BADSIG macro is renamed to SIG_ERR .

A.2.7 <stdio.h>

The <stdio.h> header file now defines the type size_t and no longer includes <stdarg.h> . The v*printf functions are now prototyped using the type that va_list is defined to be (that is, char * ).

In strict ANSI C mode, the following macros are not visible: TRUE , FALSE , SEEK_EOF , OPEN_MAX , L_ctermid , L_cuserid , L_lcltmpnam , L_nettmpnam , and FILE_TYPE . In strict ANSI C mode, the following functions are not visible: fgetname , fdopen , getw , and putw .

The rename function is added.

The fflush function is modified so that a null argument causes it to flush all files.

The printf function is modified to provide the following support:

  • The %i conversion is supported.
  • The "0" flag works properly in conjunction with other flags and with all conversion specifiers. The long double type and the h modifier are now supported.
  • The %d and %i specifiers interpret the precision specification.

The scanf function is modified to handle white space as specified by the ANSI C Standard. The %p specifier is added. The L flag for long double is added.

The clearerr , feof , and ferror macros are now provided as both macros and functions. By default, they are accessed as macros. To access them as functions, perform an #undef on the macro of the same name. For example:


#undef clearerr 

A.2.8 <stdlib.h>

The <stdlib.h> header file is modified to define size_t and wchar_t directly, rather than including <stddef.h> . The names of the DIV_T and LDIV_T structures now begin with underscores.

The MB_CUR_MAX macro is added.

The multibyte character and string functions mblen , mbtowc , wctomb , mbstowcs and wcstombs are added as specified in Sections 4.10.7 and 4.10.8 of the ANSI C Standard.

The abort() function is changed to only raise a SIGABRT signal.

A.2.9 <string.h>

The strcoll and strxfrm functions are added as specified in the ANSI C Standard, Sections 4.11.4.3 and 4.11.4.5.

A.2.10 <time.h>

In strict and relaxed ANSI C modes, the following changes apply to the <time.h> header file:

  • CLOCKS_PER_SEC is defined instead of CLK_TCK .
  • The size_t and time_t types are defined, and the <types.h> and <timeb.h> header files are not included.
  • The times and ftime functions, and the struct tbuffer , tbuffer_t , and tm_t types must not be defined in your source code.

The mktime and strftime functions are added as specified in the ANSI C Standard, Sections 4.12.2.3 and 4.12.3.5, respectively.

A.3 Unsupported Features

Compaq C for OpenVMS Systems does not support parallel processing on either OpenVMS VAX or OpenVMS Alpha systems and, therefore, does not support the following qualifiers and preprocessor directives:

/[NO]PARALLEL
/SHOW=NODECOMPOSITION
#pragma ignore_dependency
#pragma safe_call
#pragma sequential_loop


Appendix B
Common Pitfalls

This appendix contains some of the most common pitfalls you might encounter while using Compaq C. Symptoms, examples, and solutions are described.

Symptom:

The compiler generates an "Insufficient Virtual Memory" error.

Solution:

Increase the PAGEFILEQUO process quota and/or the VIRTUALPAGCNT sysgen parameter.

Symptom:

The compiler does not recognize expected routine entry points.

Example:


$ type main.c 
main() 
{ 
  exit(1); 
} 
$ cc main.c 
exit(1); 
..^ 
%CC-I-IMPLICITFUNC, In this statement, the identifier 
exit is implicitly declared as a function. 

Solutions:

  1. In ANSI mode, include function prototypes (such as #include <stdlib.h> ) in this example.
  2. Compile using the /STANDARD=VAXC qualifier.

Symptom:

The compiler generates a %CC-E-NOTCOMPAT error message for seemingly correct code.

Example:


$ type main.c 
void foo(short a); 
void foo(a) 
  short a; 
{} 
$ cc main.c 
                   
 
void foo(a) 
.....^ 
 
%CC-E-NOTCOMPAT, In this declaration, the type of foo is not compatible 
with the types of previous declarations of foo. 

This example represents a mixing of new-style function prototypes and old-style function declarations. In the following declaration, the argument a gets widened to int on entry to foo before being converted to type short :


void foo(a) 
short a; 

Consequently the compiler detects a type mismatch. The example can be generalized to float variables, or any combination of ( unsigned ) char or short arguments.

Solutions:

  1. Replace the new-style function prototype with an old-style function definition:


    void foo(); 
    void foo(a) 
    short a; 
    {} 
    

  2. Replace the old-style function declaration with a new-style function declaration:


    void foo(short a); 
    void foo(short a) 
    {} 
    

Symptom:

Include-file lookups do not include the anticipated files.

Example:

By default, Compaq C for OpenVMS Systems first searches the directory containing the top-level source file. Consider the following files and the #include statements they contain:


[]main.c 
   #include "[.sub1]a.h" 
 
[.sub1]a.h 
   #include "b.h" 
                                 
[.sub1]b.h 
   "In [.sub1]" 
 
[.sub2]b.h 
  "In [.sub2]" 

Compiling with the following command includes the [.sub2]b.h header file:


cc/include=[.sub2]main.c 

Solution:

Specify /NESTED_INCLUDE_DIRECTORY in order to first search the directory containing the top-level source file (not the directory of the source file containing the #include directive).

Symptom:

VAX C extensions to the language are not accepted by the compiler.

Example:


int _align (word) w1; 
....^ 
%CC-W-ALIGNEXT, _align is a language extension. 

Solution:

Compile using the /STANDARD=VAXC qualifier.

Symptom:

The compiler generates a ADDRCONSTEXT (warning in /STANDARD=RELAXED mode and error in /STANDARD=ANSI mode) for seemingly correct code.

Example:


$ type main.c 
struct dsc$descriptor_s 
{ 
  unsigned short dsc$w_length; 
  unsigned char dsc$b_dtype; 
  unsigned char dsc$b_class; 
  char *dsc$a_pointer; 
}; 
 
main() 
{ 
  char name[5]; 
  struct dsc$descriptor_s name_dsc = { 
  sizeof(name)-1, 14, 1, name }; 
} 
 
$ cc main.c 
 
sizeof(name)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S, name }; 
..............................................^ 
%CC-W-ADDRCONSTEXT, In the initializer for name_dsc.dsc$a_pointer, 
"name" does not have a constant address, but occurs in a context that 
requires an address constant. This is an extension of the language. 

Solution:

Section 3.5.7 of the ANSI Standard restricts allowable automatic aggregate initializion. The Compaq C compiler does not have this restriction in /STANDARD=VAXC mode. Use any of the following solutions.

  • Declare the array name to be static:


    static char name[5]; 
    

  • Compile in /STANDARD=VAXC mode.
  • Compile with /WARNING=DISABLE=ADDRCONSTEXT.
  • Insert the #pragma [no]standard preprocessor directive to suppress the warning message:


    #pragma __nostandard 
    struct dsc$descriptor_s name_dsc = { 
        sizeof(name)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S, name }; 
         } 
    #pragma __standard 
    


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