DEC C

DEC C

Language Reference Manual

Order Number: AA--PUNDD--TK1


February 1998

This document is the language reference manual for DEC C.

Revision Update Information: This revised manual supersedes the DEC C Language Reference Manual (Order No. AA--PUNDC--TK).

Software Version: DEC C Version 5.7 for OpenVMS Systems

DEC C Version 5.6 for DIGITAL UNIX Version 4.0D

Digital Equipment Corporation
Maynard, Massachusetts

The information in this document is subject to change without notice and should not be construed as a commitment by Digital Equipment Corporation. Digital Equipment Corporation assumes no responsibility for any errors that may appear in this document.

The software described in this document is furnished under a license and may be used or copied only in accordance with the terms of such license.

The following are trademarks of Digital Equipment Corporation: DEC, DECnet, DECtalk, DECthreads, Digital, OpenVMS, RMS, VAX, VAX C, VAX DOCUMENT, VMS, and the DIGITAL logo

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.

This document is available on CD--ROM.

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

Contents Index


Preface

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

Digital has changed the name of its UNIX operating system from DEC OSF/1 to DIGITAL UNIX. The new name reflects Digital's commitment to UNIX and its conformance to UNIX standards.

DEC 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, DEC 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 DEC C document by sending electronic mail to the following Internet address:

decc_docs@bookie.enet.dec.com

Note

1 Digital 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 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 DEC C documentation (user's guide and online help for OpenVMS systems, programmer's guide and manpages for Digital 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 DEC C data types and type qualifiers.

Chapter 4 describes the declaration of identifiers in DEC 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 Digital's ANSI conformance, 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 DEC C using the common C compatibility option.

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

Associated Documents

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

The printed version of the DIGITAL UNIX documentation set is color coded to help specific audiences quickly find the books that meet their needs. (You can order the printed documentation from Digital.) This color coding is reinforced with the use of an icon on the spines of books. The following list describes this convention:
Audience Icon Color Code
General users G Blue
System and network administrators S Red
Programmers P Purple
Device driver writers D Orange
Reference page users R Green

Some books in the DIGITAL UNIX documentation set help meet the needs of several audiences. For example, the information in some system books is also used by programmers. Keep this in mind when searching for information on specific topics.

The Documentation Overview, Glossary, and Master Index provides information on all of the books in the DIGITAL UNIX documentation set.

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.
Digital UNIX
DIGITAL UNIX
References to Digital UNIX and DIGITAL UNIX refer to the same operating system.
[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.
DEC C also allows ... DEC 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 DEC C Version 5.7 to reflect DEC C support for:


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