Tru64 UNIX

Tru64 UNIX

Compaq C Language Reference Manual

Order Number: AA--RH9ND--TE


June 2001

This document is the language reference manual for Compaq C.

Revision Update Information: This revised manual supersedes the Compaq C Language Reference Manual (Order No. AA--RH9NC--TE).

Software Version: Compaq C for Tru64 UNIX Version 5.1A or higher

Compaq C Version 6.4 for OpenVMS Systems

Compaq Computer Corporation
Houston, Texas


First Printing, February 1991 Revised, June 2001

COMPAQ, the Compaq logo, and VAX Registered in U.S. Patent and Trademark Office. Tru64, Alpha, and OpenVMS are trademarks of Compaq Information Technologies Group, L.P. UNIX is a trademark of The Open Group in the United States and other countries. All other product names mentioned herein may be trademarks of their respective companies.

Confidential computer software. Valid license from Compaq required for possession, use, or copying. Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor's standard commercial license.

Compaq shall not be liable for technical or editorial errors or omissions contained herein. The information in this document is provided as is without warranty of any kind and is subject to change without notice. The warranties for Compaq products are set forth in the express limited warranty statements accompanying such products. Nothing herein should be construed as constituting an additional warranty.

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 Compaq OpenVMStm VAX® and Compaq OpenVMS Alpha systems, Compaq Tru64tm UNIX systems, and Linux Alpha systems. Tru64 UNIX runs on Alpha processors.

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.

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 reference pages 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:

New and Changed Features

Compaq C Version 6.4 provides most of the language-feature support for the new C99 standard (ISO/IEC 9899:1999 published by ISO in December, 1999 and adopted as an ANSI standard in April, 2000).

This version also adds new command-line options and pragmas (see the Programmer's Guide and reference pages), and a new version of the GEM optimizing back end for Alpha systems.

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

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 HTML version of the 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.

Reader's Comments

Compaq welcomes any comments and suggestions you have on this and other Tru64 UNIX manuals. You can send your comments in the following ways:

Please include the following information along with your comments:

The Tru64 UNIX Publications group cannot respond to system problems or technical support inquiries. Please address technical questions to your local system vendor or to the appropriate Compaq technical support office. Information provided with the software media explains how to send problem reports to Compaq.


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