DIGITAL UNIX
DEC C Language Reference Manual

Order Number: AA-QTLTB-TE

December 1997

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-QTLTA-TE).

Software Version: DEC C Version 5.6 for OpenVMS Systems
DEC C Version 5.6 for Digital UNIX Version 4.0D

Digital Equipment Corporation
Maynard, Massachusetts

©Digital Equipment Corporation 1991, 1992, 1995, 1996, 1997. All Rights Reserved.

Contents

Preface

1 Lexicon

1.1 Character Set

1.1.1 Trigraph Sequences

1.1.2 Digraph Sequences

1.2 Identifiers

1.3 Comments

1.4 Keywords

1.5 Operators

1.6 Punctuators

1.7 String Literals

1.8 Constants

1.8.1 Integer Constants

1.8.2 Floating-Point Constants

1.8.3 Character Constants

1.8.3.1 Wide Characters

1.8.3.2 Multibyte Characters

1.8.3.3 Character Escape Sequences

1.8.3.4 Numeric Escape Sequences

1.8.4 Enumeration Constants

1.9 Header Files

1.10 Limits

1.10.1 Translation Limits

1.10.2 Numerical Limits

1.10.3 Character Display

2 Basic Concepts

2.1 Blocks

2.2 Compilation Units

2.3 Scope

2.3.1 File Scope

2.3.2 Block Scope

2.3.3 Function Scope

2.3.4 Function Prototype Scope

2.4 Visibility

2.5 Side Effects and Sequence Points

2.6 Incomplete Type

2.7 Compatible and Composite Types

2.8 Linkage

2.9 Tentative Definitions

2.10 Storage Classes

2.10.1 The auto Class

2.10.2 The register Class

2.10.3 The static Class

2.10.4 The extern Class

2.11 Forward References

2.12 Tags

2.13 lvalues and rvalues

2.14 Name Spaces

2.15 Preprocessing

2.16 Type Names

3 Data Types

3.1 Data Sizes

3.2 Integral Types

3.2.1 Non-Character Types

3.2.2 Character Types

3.3 Floating-Point Types

3.4 Derived Types

3.4.1 Function Type

3.4.2 Pointer Type

3.4.3 Array Type

3.4.4 Structure Type

3.4.5 Union Type

3.5 void Type

3.6 Enumerated Types

3.7 Type Qualifiers

3.7.1 const Type Qualifier

3.7.2 volatile Type Qualifier

3.7.3 __unaligned Type Qualifier

3.7.4 __restrict Type Qualifier

3.7.4.1 Rationale

3.7.4.1.1 Aliasing

3.7.4.1.2 Library Examples

3.7.4.1.3 Overlapping Objects

3.7.4.1.4 Restricted Pointer Prototype for memcpy

3.7.4.2 Formal Definition of the __restrict Type Qualifier

3.7.4.3 Examples

3.7.4.3.1 File Scope Restricted Pointers

3.7.4.3.2 Function Parameters

3.7.4.3.3 Block Scope

3.7.4.3.4 Members of Structures

3.7.4.3.5 Type Definitions

3.7.4.3.6 Expressions Based on Restricted Pointers

3.7.4.3.7 Assignments between Restricted Pointers

3.7.4.3.8 Assignments to Unrestricted Pointers

3.7.4.3.9 Ineffective Uses of Type Qualifiers

3.7.4.3.10 Constraint Violations

3.8 Type Definition

4 Declarations

4.1 Declaration Syntax Rules

4.2 Initialization

4.3 External Declarations

4.4 Declaring Simple Objects

4.4.1 Initializing Simple Objects

4.4.2 Declaring Integer Objects

4.4.3 Declaring Character Variables

4.4.4 Declaring Floating-Point Variables

4.5 Declaring Enumerations

4.6 Declaring Pointers

4.6.1 Declaring void Pointers

4.6.2 Initializing Pointers

4.7 Declaring Arrays

4.7.1 Initializing Arrays

4.7.2 Pointers and Arrays

4.8 Declaring Structures and Unions

4.8.1 Similarities Between Structures and Unions

4.8.2 Differences Between Structures and Unions

4.8.3 Bit Fields

4.8.4 Initializing Structures

4.8.5 Initializing Unions

4.9 Declaring Tags

4.10 Declaring Type Definitions

5 Functions

5.1 Function Calls

5.2 Function Types

5.3 Function Definitions

5.4 Function Declarations

5.5 Function Prototypes

5.5.1 Prototype Syntax

5.5.2 Scope and Conversions

5.6 Parameters and Arguments

5.6.1 Argument Conversions

5.6.2 Function and Array Identifiers as Arguments

5.6.3 Passing Arguments to the main Function

6 Expressions and Operators

6.1 Primary Expressions

6.1.1 Identifiers

6.1.2 Constants

6.1.3 String Literals

6.1.4 Parenthesized Expressions

6.2 Overview of the C Operators

6.3 Postfix Operators

6.3.1 Array References

6.3.2 Function Calls

6.3.3 Structure and Union References

6.3.4 Postfix Increment and Decrement Operators

6.4 Unary Operators

6.4.1 Unary Plus and Minus

6.4.2 Logical Negation

6.4.3 Prefix Increment and Decrement Operators

6.4.4 Address Operator and Indirection

6.4.5 Bitwise Negation

6.4.6 The Cast Operator

6.4.7 The sizeof Operator

6.5 Binary Operators

6.5.1 Multiplicative Operators

6.5.2 Additive Operators

6.5.3 Shift Operators

6.5.4 Relational Operators

6.5.5 Equality Operators

6.5.6 Bitwise Operators

6.5.7 Logical Operators

6.6 Conditional Operator

6.7 Assignment Operators

6.8 Comma Operator

6.9 Constant Expressions

6.9.1 Integral Constant Expressions

6.9.2 Arithmetic Constant Expressions

6.9.3 Address Constants

6.10 Data-Type Conversions

6.10.1 Usual Arithmetic Conversions

6.10.1.1 Characters and Integers

6.10.1.2 Signed and Unsigned Integers

6.10.1.3 Floating and Integral

6.10.1.4 Floating Types

6.10.2 Pointer Conversions

6.10.3 Function Argument Conversions

7 Statements

7.1 Labeled Statements

7.2 Compound Statements

7.3 Expression Statements

7.4 Null Statements

7.5 Selection Statements

7.5.1 The if Statement

7.5.2 The switch Statement

7.6 Iteration Statements

7.6.1 The while Statement

7.6.2 The do Statement

7.6.3 The for Statement

7.7 Jump Statements

7.7.1 The goto Statement

7.7.2 The continue Statement

7.7.3 The break Statement

7.7.4 The return Statement

8 Preprocessor Directives and Predefined Macros

8.1 Macro Definition (#define and #undef)

8.1.1 Object-Like Form

8.1.2 Function-Like Form

8.1.2.1 Rules for Specifying Macro Definitions

8.1.2.2 Rules for Specifying Macro References

8.1.2.3 Side Effects in Macro Arguments

8.1.3 Conversions to String Literals (#)

8.1.4 Token Concatenation(##)

8.2 Conditional Compilation (#if, #ifdef, #ifndef, #else, #elif, #endif, and defined)

8.2.1 The #if Directive

8.2.2 The #ifdef Directive

8.2.3 The #ifndef Directive

8.2.4 The #else Directive

8.2.5 The #elif Directive

8.2.6 The #endif Directive

8.2.7 The defined Operator

8.3 File Inclusion (#include)

8.4 Explicit Line Numbering (#line)

8.5 Implementation-Specific Preprocessor Directive (#pragma)

8.6 Error Directive (#error)

8.7 Null Directive (#)

8.8 Predefined Macro Names

8.8.1 The __DATE__ Macro

8.8.2 The __FILE__ Macro

8.8.3 The __LINE__ Macro

8.8.4 The __TIME__ Macro

8.8.5 The __STDC__ Macro

8.8.6 System-Identification Macros

9 The ANSI C Standard Library

9.1 Diagnostics (<assert.h>)

9.2 Character Processing (<ctype.h>)

9.3 Error Codes (<errno.h>)

9.4 ANSI C Limits (<limits.h> and <float.h>)

9.5 Localization (<locale.h>)

9.6 Mathematics (<math.h>)

9.7 Nonlocal Jumps (<setjmp.h>)

9.8 Signal Handling (<signal.h>)

9.9 Variable Arguments (<stdarg.h>)

9.10 Common Definitions (<stddef.h>)

9.11 Standard Input/Output (<stdio.h>)

9.12 General Utilities (<stdlib.h>)

9.13 String Processing (<string.h>)

9.14 Date and Time (<time.h>)

A Language Syntax Summary

B ANSI Conformance Summary

B.1 Diagnostics (§2.1.1.3)

B.2 Hosted Environment (§2.1.2.2)

B.3 Multibyte Characters (§2.2.1.2)

B.4 Escape Sequences (§2.2.2)

B.5 Translation Limits (§2.2.4.1)

B.6 Numerical Limits (§2.2.4.2)

B.7 Keywords (§3.1.1)

B.8 Identifiers (§3.1.2)

B.9 Linkages of Identifiers (§3.1.2.2)

B.10 Types (§3.1.2.5)

B.11 Integer Constants (§3.1.3.2)

B.12 Character Constants (§3.1.3.4)

B.13 String Literals (§3.1.4)

B.14 Operators-Compound Assignment (§3.1.5)

B.15 Characters and Integers-Value-Preserving Promotions (§3.2.1.1)

B.16 Signed and Unsigned Integer Conversions (§3.2.1.2)

B.17 Floating and Integral Conversions (§3.2.1.3)

B.18 Pointer Conversions (§3.2.2.3)

B.19 Structure and Union Members (§3.3.2.3)

B.20 The sizeof Operator (§3.3.3.4)

B.21 Cast Operators (§3.3.4)

B.22 Multiplicative Operators (§3.3.5)

B.23 Additive Operators (§3.3.6)

B.24 Bitwise Shift Operators (§3.3.7)

B.25 Storage-Class Specifiers (§3.5.1)

B.26 Type Specifiers (§3.5.2)

B.27 Structure and Union Specifiers (§3.5.2.1)

B.28 Variant Structures and Unions

B.29 Structure Alignment

B.30 Enumeration Specifiers (§3.5.2.2)

B.31 Type Qualifiers (§3.5.3)

B.32 Declarators (§3.5.4)

B.33 Initialization (§3.5.7)

B.34 The switch Statement (§3.6.4.2)

B.35 External Object Definitions (§3.7.2)

B.36 Conditional Inclusion (§3.8.1)

B.37 Source File Inclusion (§3.8.2)

B.38 Macro Replacement-Predefined Macro Names (§3.8.3)

B.39 The ## Operator (§3.8.3.3)

B.40 Error Directive (§3.8.5)

B.41 Pragma Directive (§3.8.6)

B.42 Function Inline Expansion

B.43 Linkage Pragmas

B.44 Other Pragmas

C ASCII Equivalence Table

D Common C Extensions Supported by DEC C

D.1 Extensions Compatible with ANSI C

D.2 Extensions Incompatible with ANSI C

E VAX C Extensions Supported by DEC C

E.1 Extensions Compatible with ANSI C

E.2 Extensions Incompatible with ANSI C

Index

Examples

4-1 The Rules for Initializing Structures

5-1 Declaring Functions Passed as Arguments

7-1 Using switch to Count Blanks, Tabs, and New Lines

Figures

C-1 ASCII Equivalence Chart

Tables

1-1 Trigraph Sequences

1-2 Digraph Sequences

1-3 Keywords

1-4 Punctuators

1-5 Floating-Point Notation

1-6 Character Escape Sequences

2-1 Type Name Examples

3-1 Basic Data Types

3-2 Sizes and Ranges of Data Types

6-1 C Operators

6-2 Precedence of C Operators

9-1 File Modes

9-2 strftime Conversion Specifiers

B-1 Digital UNIX Predefined Macro Names

B-2 OpenVMS VAX and Alpha Predefined Macro Names

B-3 Library Routine Standards Conformance Macros-All platforms


Previous Page | Next Page | Table of Contents | Index