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

Compaq C

Compaq C

Language Reference Manual

Order Number: AA--PUNDF--TK


November 1999

This document is the language reference manual for Compaq C.

Revision Update Information: This is a revised manual, replacing AA--PUNDE--TK.

Software Version: Compaq C Version 6.2 for OpenVMS Systems

Compaq C Version 6.1 for Tru64 UNIX Version 5.0 or higher

Compaq Computer Corporation
Houston, Texas


First Printing, February 1991 Revised, November 1992 Revised, November 1995 Revised, March 1996 Revised, May 1997 Revised, February 1998 Revised, December 1998 Revised, November 1999

Digital Equipment Corporation makes no representations that the use of its products in the manner described in this publication will not infringe on existing or future patent rights, nor do the descriptions contained in this publication imply the granting of licenses to make, use, or sell equipment or software in accordance with the description.

Possession, use, or copying of the software described in this publication is authorized only pursuant to a valid written license from Compaq or an authorized sublicensor.

Copyright ©1991 - 1999 Digital Equipment Corporation

Compaq, the Compaq logo, Alpha, DEC, DECthreads, DIGITAL, OpenVMS, Tru64 UNIX, VAX, and VMS are registered in the U.S. Patent and Trademark Office.

The following are third-party trademarks:

UNIX is a registered trademark in the United States and other countries licensed exclusively through X/Open Company Ltd.

X/Open is a trademark of the X/Open Group.

Other product names mentioned herein may be the trademarks of their respective companies.

This document is available on CD-ROM.

This document was prepared using VAX DOCUMENT, Version V3.2-1m.

Contents Index


Preface

This manual provides reference information for using the Compaq C language on Compaq systems. Compaq C is an ISO/ANSI-compliant C compiler for OpenVMS VAX and OpenVMS Alpha systems and Tru64 UNIX® systems. Tru64 UNIX runs on Alpha processors.

Compaq has changed the name of its UNIX operating system from DIGITAL UNIX to Tru64 UNIX.

Compaq C is compliant with the International Standards Organization (ISO) C Standard (ISO 9899:1990[1992]), formerly the American National Standard for Information Systems-Programming Language C (document number: X3.159-1989). By the use of command-line options, Compaq C is compatible with older dialects of C, including common usage C (Kernighan and Ritchie C) and VAX C.

This manual is based on the ISO C Standard (ISO 9899:1990[1992]), formerly the ANSI X3J11 committee's standard for the C programming language (called the ANSI C standard in this manual). 1 All library functions and language extensions to the ANSI C standard are also described.

You may send comments or suggestions regarding this manual or any Compaq C document by sending electronic mail to the following Internet address:

c_docs@zko.dec.com

Note

1 Compaq would like to thank CBEMA and its Accredited Standards Committee X3 for use of the material derived in whole or in part from the American National Standard Programming Language C. The ANSI C standard may be purchased from the ANSI Sales Department by calling the United States telephone number 1-212-642-4900.

Intended Audience

This manual is intended for programmers who need reference information on the Compaq C (formerly DEC C) language. There is little task-oriented material or platform-specific material in this manual; for that type of information, see your platform-specific Compaq C documentation (user's guide and online help for OpenVMS systems, programmer's guide and manpages for Tru64 UNIX systems.)

Purpose of the ANSI Standard

The ANSI C standard was developed by a committee of program developers and knowledgeable C users to address the problems caused by inexact specification of the C language. These problems were primarily related to portability of programs between different types of machines. The committee analyzed the language for areas where its syntax and semantics were vague or indeterminate, and then chose precise definitions for those C constructs. The result is an unambiguous, machine-independent definition.

The ANSI C standard states that it:

" specifies the form and establishes the interpretation of programs expressed in the programming language C. [The standard's] purpose is to promote portability, reliability, maintainability, and efficient execution of C language programs on a variety of computing systems. "

The standard specifies:

The ANSI C standard does not specify:

Manual Structure

This manual has the following chapters and appendixes:

Chapter 1 describes the elements of the C language.

Chapter 2 discusses some of the basic concepts underlying the C language.

Chapter 3 explains Compaq C data types and type qualifiers.

Chapter 4 describes the declaration of identifiers in Compaq C. The declaration of constants, variables, structures, unions, pointers, and arrays is covered.

Chapter 5 describes function calls, function declarations, function definitions, function parameters, and function arguments.

Chapter 6 discusses the types of expressions you can build in C. It also explains the effects of operators available in C, including unary, binary, conditional, primary, and postfix operators.

Chapter 7 describes the C statements that provide flow control, conditional executions, looping, and interruption.

Chapter 8 explains the purpose of the C preprocessor directives and predefined macros.

Chapter 9 lists and describes the functions, macros, and types in the ANSI C standard library, arranged by header file.

Appendix A provides a syntax summary of all C language constructs.

Appendix B describes the extent of the ANSI conformance of Compaq C, including exceptions and extensions to the standard.

Appendix C provides the ASCII octal, decimal, and hexadecimal equivalents for each character in the ASCII character set.

Appendix D lists the common C extensions supported by Compaq C using the common C compatibility option.

Appendix E lists the VAX C extensions supported by Compaq C using the VAX C compatibility option.

Associated Documents

You may find the following documents useful when programming in Compaq C:

Note

2 Brian W. Kernighan and Dennis M. Ritchie, The C Programming Language (Englewood Cliffs, New Jersey: Prentice Hall, 1988).

Conventions Used in this Document

Convention Meaning
OpenVMS systems Refers to OpenVMS VAX and OpenVMS Alpha systems unless otherwise specified.
[Return] The symbol [Return] represents a single stroke of the Return key on a terminal.
[Ctrl/X] The symbol [Ctrl/X], where X represents a terminal control character, represents holding down the Ctrl key while pressing the specified terminal character key.
Compaq C also allows ... Compaq C extensions to the ANSI C standard are shown in teal blue in the printed manual and HTML manual.
float x;
.
.
.
x = 5;
A vertical ellipsis indicates that not all of the text of a program or program output is shown. Only relevant material is shown in the example.
option,... A horizontal ellipsis indicates that additional parameters, options, or values can be entered. A comma preceding the ellipsis indicates that successive items must be separated by commas.
syntax opt Optional syntax elements are indicated with the subscripted abbreviation opt. Isolated syntax diagrams in individual sections of this manual may require reference to Appendix A to determine the complete syntax for a construct. For instance, the ANSI C standard syntax includes a constant as a potential assignment-expression.
storage-class-specifier :
auto
static
register
In syntax definitions, items appearing on separate lines are mutually exclusive alternatives.
The auto storage class...
The fprintf function...
Monospaced type identifies language keywords, the names of independently compiled external functions and files, syntax summaries, and references to variables or identifiers introduced in an example.

New and Changed Features

This manual was revised for Compaq C Version 6.2 to reflect the following new features:

Also see the Compaq C release notes for a comprehensive list of enhancements and fixes.


Chapter 1
Lexicon

C, like any language, uses a standard grammar and character set. The specific elements that comprise this grammar and character set are described in the following sections:

C compilers interpret source code as a stream of characters from the source file. These characters are grouped into tokens, which can be punctuators, operators, identifiers, keywords, string literals, or constants. Tokens are the smallest lexical element of the language. The compiler forms the longest token possible from a given string of characters; the token ends when white space is encountered, or when the next character could not possibly be part of the token.

White space can be a space character, new-line character, tab character, form-feed character, or vertical tab character. Comments are also considered white space. Section 1.1 lists all the white space characters. White space is used as a token separator (except within quoted strings), but is otherwise ignored in the character stream, and is used mainly for human readability. White space may also be significant in preprocessor directives (see Chapter 8).

Consider the following source code line:


static int x=0;  /* Could also be written "static int x = 0;"   */ 

The compiler breaks the previous line into the following tokens (shown one per line):


static 
int 
x 
= 
0 
; 

As the compiler processes the input character stream, it identifies tokens and locates error conditions. The compiler can identify three types of errors:

Logical errors are not identified by the compiler.

An important concept throughout C is the idea of a compilation unit, which is one or more files compiled by the compiler.

Note

The ANSI C standard refers to compilation units as translation units. This text treats these terms as equivalent.

The smallest acceptable compilation unit is one external definition. The ANSI C standard defines several key concepts in terms of compilation units. Section 2.2 discusses compilation units in detail.

A compilation unit with no declarations is accepted with a compiler warning in all modes except for the strict ANSI standard mode.

1.1 Character Set

A character set defines the valid characters that can be used in source programs or interpreted when a program is running. The source character set is the set of characters available for the source text. The execution character set is the set of characters available when executing a program. The source character set does not necessarily match the execution character set; for example, when the execution character set is not available on the devices used to produce the source code.

Different character sets exist; for example, one character set is based on the American Standard Code for Information Interchange (ASCII) definition of characters, while another set includes the Japanese kanji characters. The character set in use makes no difference to the compiler; each character simply has a unique value. C treats each character as a different integer value. The ASCII character set has fewer than 255 characters, and these characters can be represented in 8 bits or less. However, in some extended character sets, so many characters exist that some characters' representation requires more than 8 bits. A special type was created to accommodate these larger characters, called the wchar_t (or wide character) type. Section 1.8.3.1 discusses wide characters further.

Most ANSI-compatible C compilers accept the following ASCII characters for both the source and execution character sets. Each ASCII character corresponds to a numeric value. Appendix C lists the ASCII characters and their numeric values.

In character constants and string literals, characters from the execution character set can also be represented by character or numeric escape sequences. Section 1.8.3.3 and Section 1.8.3.4 describe these escape sequences.

The ASCII execution character set also includes the following control characters:

The null character is a byte or wide character with all bits set to 0. It is used to mark the end of a character string. Section 1.7 discusses character strings in more detail.

The new-line character splits the source character stream into separate lines for greater legibility and for proper operation of the preprocessor.

Sometimes a line longer than the terminal or window width must be interpreted by the compiler as one logical line. One logical line can be typed as two or more lines by appending the backslash character ( \ ) to the end of the continued lines. The backslash must be immediately followed by a new-line character. The backslash signifies that the current logical line continues on the next line. For example:


#define ERROR_TEXT "Your entry was outside the range of \
0 to 100." 

The compiler deletes the backslash character and the adjacent new-line character during processing, so that this line becomes one logical line, as follows:


#define ERROR_TEXT "Your entry was outside the range of 0 to 100." 

A long string can be continued across multiple lines by using the backslash-newline line continuation feature, but the continuation of the string must start in the first position of the next line. In some cases, this destroys the indentation scheme of the program. The ANSI C standard introduces another string continuation mechanism to avoid this problem. Two string literals, with only white space separating them, are combined to form one logical string literal. For example:


printf ("Your entry was outside the range of " 
        "0 to 100.\n"); 

The maximum logical line length is 32,767 characters.


Next Contents Index
  

1.800.AT.COMPAQ

privacy and legal statement