ebook img

C in a Nutshell PDF

1291 Pages·2005·4.63 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview C in a Nutshell

C in a Nutshell Peter Prinz Tony Crawford Published by O’Reilly Media Beijing ⋅ Cambridge ⋅ Farnham ⋅ Köln ⋅ Sebastopol ⋅ Tokyo Preface This book is a complete reference to the C programming language and the C runtime library. As a Nutshell book, its purpose is to serve as a convenient, reliable companion for C programmers in their day-to-day work. It describes all the elements of the language and illustrates their use with numerous examples. The present description of the C language is based on the 1999 international C standard, ISO/IEC 9899:1999, including the Technical Corrigenda, TC1 of 2001 and TC2 of 2004. This standard, widely known as C99, is an extension of the ISO/IEC 9899:1990 standard and the 1995 Normative Addendum 1 (ISO/IEC 9899/AMD1:1995). The 1990 ISO/IEC standard corresponds to the ANSI standard X3.159, which was ratified in late 1989 and is commonly called ANSI C or C89. The new features of the 1999 C standard are not yet fully supported by all compilers and standard library implementations. In this book we have therefore labeled 1999 extensions, such as new standard library functions that were not mentioned in earlier standards, with the abbreviation C99. This book is not an introduction to programming in C. Although it covers the fundamentals of the language, it is not organized or written as a tutorial. If you are new to C, we assume that you have read at least one of the many introductory books, or that you are familiar with a related language, such as Java or C++. How This Book Is Organized This book is divided into three parts. The first part describes the C language in the strict sense of the term; the second part describes the standard library; and the third part describes the process of compiling and testing programs with the popular tools in the GNU software collection. Part I Part I, which deals with the C language, includes Chapters 1 through 14. After Chapter 1, which describes the general concepts and elements of the language, each chapter is devoted to a specific topic, such as types, statements, or pointers. Although the topics are ordered so that the fundamental concepts for each new topic have been presented in an earlier chapter—types, for example, are described before expressions and operators, which come before statements, and so on—you may sometimes need to follow references to later chapters to fill in related details. For example, some discussion of pointers and arrays is necessary in Chapter 5 (which covers expressions and operators), even though pointers and arrays are not described in full detail until Chapters 8 and 9. Chapter 1, Language Basics Describes the characteristics of the language and how C programs are structured and compiled. This chapter introduces basic concepts such as the translation unit, character sets, and identifiers. Chapter 2, Types Provides an overview of types in C and describes the basic types, the type void, and enumerated types. Chapter 3, Literals Describes numeric constants, character constants, and string literals, including escape sequences. Chapter 4, Type Conversions Describes implicit and explicit type conversions, including integer promotion and the usual arithmetic conversions. Chapter 5, Expressions and Operators Describes the evaluation of expressions, all the operators, and their compatible operands. Chapter 6, Statements Describes C statements such as blocks, loops, and jumps. Chapter 7, Functions Describes function definitions and function calls, including recursive and inline functions. Chapter 8, Arrays Describes fixed-length and variable-length arrays, including strings, array initialization, and multidimensional arrays. Chapter 9, Pointers Describes the definition and use of pointers to objects and functions. Chapter 10, Structures, Unions, and Bit-Fields Describes the organization of data in these user-defined derived types. Chapter 11, Declarations Describes the general syntax of a declaration, identifier linkage, and the storage duration of objects. Chapter 12, Dynamic Memory Management Describes the standard library's dynamic memory management functions, illustrating their use in a sample implementation of a generalized binary tree. Chapter 13, Input and Output Describes the C concept of input and output, with an overview of the use of the standard I/O library. Chapter 14, Preprocessing Directives Describes the definition and use of macros, conditional compiling, and all the other preprocessor directives and operators. Part II Part II, consisting of Chapters 15, 16, and 17, is devoted to the C standard library. It provides an overview of standard headers and also contains a detailed function reference. Chapter 15, The Standard Headers Describes contents of the headers and their use. The headers contain all of the standard library's macros and type definitions. Chapter 16, Functions at a Glance Provides an overview of the standard library functions, organized by areas of application, such as "Mathematical Functions," "Time and Date Functions," and so on. Chapter 17, Standard Library Functions Describes each standard library function in detail, in alphabetical order, and contains examples to illustrate the use of each function. Part III The third part of this book provides the necessary knowledge of the C programmer's basic tools: the compiler, the make utility, and the debugger. The tools described here are those in the GNU software collection. Chapter 18, Compiling with GCC Describes the principal capabilities that the widely used compiler offers for C programmers. Chapter 19, Using make to Build C Programs Describes how to use the make program to automate the compiling process for large programs. Chapter 20, Debugging C Programs with GDB Describes how to run a program under the control of the GNU debugger and how to analyze programs' runtime behavior to find logical errors. Further Reading In addition to works mentioned at appropriate points in the text, there are a number of resources for readers who want more technical detail than even this book can provide. The international working group on C standardization has an official home page at http://www.open-std.org/jtc1/sc22/wg14, with links to the latest version of the C99 standard and current projects of the working group. For readers who are interested in not only the what and how of C, but also the why, the WG14 site also has a link to the "C99 Rationale": this is a nonnormative but current document that describes some of the motivations and constraints involved in the standardization process. The C89 Rationale is online at http://www.lysator.liu.se/c/rat/title.html. Furthermore, for those who may wonder how C "got to be that way" in the first place, the originator of C, Dennis Ritchie, has an article titled "The Development of the C Language" as well as other historical documents on his Bell Labs web site, http://cm.bell- labs.com/cm/cs/who/dmr. Readers who want details on floating-point math beyond the scope of C may wish to start with David Goldberg's thorough introduction, "What Every Computer Scientist Should Know About Floating-Point Arithmetic," currently available online at http://docs.sun.com/source/806-3568/ncg_goldberg.html. Conventions Used in This Book The following typographical conventions are used in this book: Italic Highlights new terms; indicates filenames, file extensions, URLs, directories, and Unix utilities. Constant width Indicates all elements of C source code: keywords, operators, variables, functions, macros, types, parameters, and literals. Also used for console commands and options, and the output from such commands. Constant width bold Highlights the function or statement under discussion in code examples. In compiler, make, and debugger sessions, this font indicates command input to be typed literally by the user. Constant width italic Indicates parameters in function prototypes, or placeholders to be replaced with your own values. Plain text Indicates keys such as Return, Tab, and Ctrl. TIP This icon signifies a tip, suggestion, or general note. WARNING This icon signifies a warning or caution. Using Code Examples This book is here to help you get your job done. In general, you may use the

Description:
Learning a language--any language--involves a process wherein you learn to rely less and less on instruction and more increasingly on the aspects of the language you've mastered. Whether you're learning French, Java, or C, at some point you'll set aside the tutorial and attempt to converse on your o
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.