C, a Reference Manual

C, a Reference Manual

by Samuel P. Harbison, Guy L. Steele

View All Available Formats & Editions

This fourth edition of the bestselling C reference covers two important developments: the ISO C Amendment 1 (1994), which specifies new facilities for writing portable, international programs in C; and a discussion of how to write C programs that are compatible with C++.


  • Reveals the weaknesses in the standard C language for


This fourth edition of the bestselling C reference covers two important developments: the ISO C Amendment 1 (1994), which specifies new facilities for writing portable, international programs in C; and a discussion of how to write C programs that are compatible with C++.


  • Reveals the weaknesses in the standard C language for creating an international standard.
  • Explains the major additions to C created by ISO C Amendment 1 (1994) for writing portable, international programs.
  • Details three new standard header files: iso646.h, wctype.h, and wchar.h.
  • Explains several new tokens and macros used as replacements for operators and punctuation characters that are not found in some countries character sets.
  • Describes some new formatting codes for the printf/scanf family of functions.
  • Addresses a large number of new functions, plus some types and constants for multibyte and wide characters.
  • Shows how to write Clean C programs that are maximally portable and reusable in C and C++ environments.
  • Includes chapter-end exercises throughout the text, with detailed answers in an Appendix section.
  • Offers an Appendix of the ASCII character set.
  • Includes an Appendix of the syntax of the C language.

Editorial Reviews

A reference manual describing C language, run-time libraries, and a style of C programming that emphasizes portability and maintainability. Reviews language standards, C programming, and syntax notation, and covers lexical elements, declarations, types, conversions, and functions in both standard C and traditional C. This fourth edition includes ANSI/ISO descriptions updated with ISO C Amendment 1 (1994), and chapter discussions on C++ compatibility. Annotation c. Book News, Inc., Portland, OR (booknews.com)

Product Details

Prent Hall Higher Ed
Publication date:
Prentice-Hall Software Series
Edition description:
3rd ed

Read an Excerpt

Chapter 1: Introduction

C is a member of the "ALGOL family" of algebraic programming languages, and is more similar to languages such as PL/I, Pascal, and Ada, and less similar to BASIC, FORTRAN, or Lisp. A collection of papers, Comparing & Assessing Programming Languages Ada, C, and Pascal, edited by Alan R. Feuer and Narain Gehani (Prentice-Hall, 1984) discusses the similarities and differences found in C, Pascal, and Ada.

Dennis Ritchie designed the C language at Bell Laboratories in about 1972, and its ancestry dates from ALGOL 60 (1960), through Cambridge's CPL (1963), Martin Richards's BCPL (1967) and Ken Thompson's B language (1970) at Bell Labs. Although C is a general-purpose programming language, it has traditionally been used for systems programming. In particular, the popular UNIX operating system is written in C. Now widely available on both UNIX and non-UNIX systems, C is increasingly popular for applications that must be ported to different computers.

C's popularity is due to several factors. First, C provides a fairly complete set of facilities for dealing with a wide variety of applications. It has all the useful data types, including pointers, structures, and strings. There is a rich set of operators and control structures. C also has a standard run-time library that includes useful functions for input/output, storage allocation, string manipulation, and other purposes.

Second, C programs are efficient. C is a small language, and its data types and operators are closely related to the operations provided directly by most computers. Said another way, there is only a small "semantic gap" between C and the computer hardware.

Third, C programs are generally quite portable across different computing systems. Although C allows the programmer to write nonportable code, the uniformity of most C implementations makes it relatively easy to move applications to different computers and operating systems,

Finally, there is a growing number of C programs and C programmers. The UNIX operating system provides a large set of tools that improve C programming productivity and can serve as starting points for new applications. Because UNIX has been used in universities for several years, many students have C and UNIX experience.

Unfortunately, some of the very characteristics of C that account for its popularity can also pose problems for programmers. For example, C's smallness is due in large part to its lack of "confining rules," but the absence of such rules can lead to error-prone programming habits. To write well-ordered programs, the C programmer often relies on a set of stylistic conventions that are not enforced by the compiler. As another example, to allow C compilers to implement operations efficiently on a variety of computers, the precise meaning of some C operators and types is intentionally unspecified. This can create problems when moving a program to another computer.

In spite of the inelegancies, the bugs, and the confusion that often accompany C, it has withstood the test of time. It remains a language in which the experienced programmer can write quickly and well. Millions of lines of code testify to its usefulness.


Although there were many introductions to C at the time we wrote the First Edition of this book, there were no detailed descriptions of the C language.

1.1.1 Traditional C

The traditional (pre-standard) language reference is the book The C Programming Language, by Brian Kemighan and Dennis Ritchie (Prentice-Hall, 1978). In fact, it is not uncommon to see references to "K&R C." However, after the book was published the language continued to evolve in small ways; some features were added and some were dropped. Usually a consensus was reached on these features, although this consensus was not always documented. Many new implementations of C added their own variations to the language. When we use the phrase "the original definition of C" in this book, we mean specifically Kernighan and Ritchie's definition, before the post-1978 changes. When we speak of "traditional C," "classic C," or "pre-ISO C," we include the generally accepted extensions in use just prior to the ANSI standard. Kernighan and Richie produced a Second Edition of The C Programming Language in 1988 which describes ANSI C.

1.1.2 ANSI C, ISO C, Standard C

In 1982 the American National Standards Institute (ANSI) formed a technical subcommittee to propose a standard for the C language and run-time libraries. The X3J11 committee, chaired by Jim Brodie, produced a standard that was formally adopted in 1989 as American National Standard X3.159-1989, referred to as "ANSI C" or more informally as "Standard C". The standardization effort involved a large number of commercial C implementors-including ourselves-and their discussions helped to clarify existing practices as well as to map out some new features. Many parts of this book have benefited from these discussions.

Recognizing that programming is an international activity, an international standardization effort was begun as ANSI C was completed. The ISO/IEC JTCI/SC22/WGI4 (C) committee, chaired by P. J. Plauger, converted the ANSI standard to an international standard, ISOJEC 9899:1990, making only minor editorial changes. WG14 is now the official home of the common C standard ("ISO C"), with XM11 having important influence representing the U. S. programming community-although, in fact, X3J11's membership is international also.

Because there is no technical difference between ISO C and the earlier ANSI C, both may be referred to as Standard C. In this book, we refer to this common language as "ISO C."

It would be difficult to list all the changes from traditional C to ISO C, but some of the changed areas include:

  • New preprocessor commands and features.

  • Function prototypes, which let you specify the argument types in a function declaration.

  • Some new keywords, including const, volatile, and signed.

  • Wide characters, wide strings, and multibyte characters.

  • Many smaller changes and clarifications to conversion rules, declarations, and type checking.

1.1.3 Amendments and Corrigenda

In 1994, WG14 produced the first extensions to the ISO C standard. Amendment I includes additional facilities to support international use of C, including more library support for foreign character sets, multibyte characters and wide characters. We have incorporated the extensions of Amendment 1 into this book, and have designated them as such in the descriptions. It may be some time before all Standard C compilers incorporate the extensions in the Amendment. The additions in Amendment 1 include:

  • three new standard header files: iso646.h, wctype.h, and wchar.h

  • several new tokens and macros used as replacements for operators and punctuation characters that are not found in some countries' character sets

  • some new formatting codes for the printf/scanf family of functions

  • a large number of new functions, plus some types and constants, for multibyte and wide characters

Also in 1994, WG14 produced the first correction to ISO C. Technical Corrigendum I to ISO C is not an extension, but is rather a"bug fix." It specifies 35 small changes to the standard which resolve inconsistencies or errors. Because these corrections affect more the exposition than the intent of the Standard, we have not explicitly noted them in this book. Of course, we have reviewed the text to be sure our interpretations are consistent with the Corrigendum.

Many groups have experimented with extensions to C. There is Concurrent C, with parallel processing features, and there is Numerical C, with some extensions designed for scientific programmers and others with particular concerns about complex numbers, arrays, floating-point arithmetic, etc. Objective C introduced object-oriented programming features to the language. These variations all have limited use so far, and we do not consider them in this book.

1.1.5 C++

The term "limited use" certainly does not apply to the programming language that started as an extension to C: C++, designed by Bjame Stroustrup at AT&T Bell Labs. The past few years have seen the C++ language rapidly gaining "mind share" among C programmers. Thanks to Borland, Microsoft, and the Free Software Foundation ("GNU"), most C programmers now have C++ implementations at hand. C++ includes many improvements over C that programmers need for large applications, including improved type checking and better support for data abstraction. However, C++ is also one of the more complex object-oriented programming languages, built around concepts that are still unfamiliar to many.

C++ is nearly-but not exactly-a superset of ISO C. It is possible to write C code in the common subset of the ISO C and C++ languages-called Clean C by some-so that the code can be compiled either as a C program or as a C++ program. Since C++ generally has more strict rules than ISO C, Clean C tends to be a good, portable subset to write in. The major changes you must consider when writing Clean C are:

  • Clean C programs must use function prototypes; old-style declarations are not permitted in C++.

  • Clean C programs must avoid using names that are reserved words in C++-, like class and virtual.

There are several other rules and differences, but they are less likely to cause problems.

Unfortunately, we can't be as precise when speaking about C++ as we can about ISO C. The C++ language has not yet been standardized, and many current C++ implementations differ in significant ways. C++ is presently undergoing international standardization, with the first public review of the draft standard scheduled to appear in 1995. The ISO C++ committee working on the standard has introduced changes which have not yet found their way into commercial implementations. Finally, the draft of the future ISO C++ standard is still changing in significant ways. When explaining how to write Clean C, we will be talking about the version C++ as specified in the Working Draft of ISO C++ at the beginning of 1994.

In this book, we will explain how to write ISO C code so that it is acceptable to C++ compilers. We will not discuss features of C++ that are not available in ISO C. (Which, of course, includes almost everything interesting in C++.)

1.1.6 The Future of C

In accordance with ISO policies on timely reexamination of standards, WG14 will consider whether a major revision of ISO C is necessary beginning in 1995. It is too soon to tell in what direction WG14 will seek to evolve C, but it is possible that the committee will recommend adopting some of the more conservative features of C++ and perhaps some numerical extensions that have been worked on by subgroups of the standards committees.

It is unlikely that WG14 will recommend abandoning C in favor of C++. Most people believe that C and C-++ address different programming problems, and that there is merit in both languages.

1.1.7 This Text

This book describes the two major variations of C: ISO C and traditional C. It also describes two variations on ISO C: the additional features in Amendment 1, and the Clean C subset of C and C++. ISO C gives implementors some freedom in how they implement the language, and so we try to describe the common variations. We also try to indicate how to write "good" C programs-programs that are readable, portable, and maintainable....

Customer Reviews

Average Review:

Write a Review

and post it to your social network


Most Helpful Customer Reviews

See all customer reviews >