C in a Nutshell: The Definitive Reference

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

The new edition of this classic O'Reilly reference provides clear, detailed explanations of every feature in the C language and runtime library, including multithreading, type-generic macros, and library functions that are new in the 2011 C standard (C11). If you want to understand the effects of an unfamiliar function, and how the standard library requires it to behave, you'll find it here, along with a typical example.

Ideal for experienced C and C++ programmers, this book also includes popular tools in the GNU software collection. You'll learn how to build C programs with GNU Make, compile executable programs from C source code, and test and debug your programs with the GNU debugger.

In three sections, this authoritative book covers:



C language concepts and language elements, with separate chapters on types, statements, pointers, memory management, I/O, and more

The C standard library, including an overview of standard headers and a detailed function reference

Basic C programming tools in the GNU software collection, with instructions on how use them with the Eclipse IDE

Author(s): Peter Prinz; Tony Crawford
Edition: 2
Publisher: O'Reilly Media
Year: 2015

Language: English
Pages: 824

Copyright
Table of Contents
Preface
How This Book Is Organized
Part I
Part II
Part III
Further Reading
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
Peter
Tony
Part I. Language
Chapter 1. Language Basics
Characteristics of C
The Structure of C Programs
Source Files
Comments
Character Sets
Wide Characters and Multibyte Characters
Universal Character Names
Digraphs and Trigraphs
Identifiers
Identifier Name Spaces
Identifier Scope
How the C Compiler Works
The C Compiler’s Translation Phases
Tokens
Chapter 2. Types
Typology
Integer Types
Integer Types Defined in Standard Headers
Floating-Point Types
Complex Floating-Point Types
Enumerated Types
The Type void
void in Function Declarations
Expressions of Type void
Pointers to void
The Alignment of Objects in Memory
Chapter 3. Literals
Integer Constants
Floating-Point Constants
Decimal Floating-Point Constants
Hexadecimal Floating-Point Constants
Character Constants
Types and Values of Character Constants
Escape Sequences
String Literals
Chapter 4. Type Conversions
Conversion of Arithmetic Types
Hierarchy of Types
Integer Promotion
Usual Arithmetic Conversions
Other Implicit Type Conversions
The Results of Arithmetic Type Conversions
Conversion of Nonarithmetic Types
Array and Function Designators
Explicit Pointer Conversions
Implicit Pointer Conversions
Conversions Between Pointer and Integer Types
Chapter 5. Expressions and Operators
How Expressions Are Evaluated
Generic Selections (C11)
Lvalues
Side Effects and Sequence Points
Operator Precedence and Associativity
Operators in Detail
Arithmetic Operators
Assignment Operators
Increment and Decrement Operators
Comparative Operators
Logical Operators
Bitwise Operators
Memory Addressing Operators
Other Operators
Constant Expressions
Integer Constant Expressions
Other Constant Expressions
Chapter 6. Statements
Expression Statements
Block Statements
Loops
while Statements
for Statements
do…while Statements
Nested Loops
Selection Statements
if Statements
switch Statements
Unconditional Jumps
The break Statement
The continue Statement
The goto Statement
The return Statement
Chapter 7. Functions
Function Definitions
Functions and Storage Class Specifiers
K&R-Style Function Definitions
Function Parameters
Arrays as Function Parameters
The main() Function
Function Declarations
Declaring Optional Parameters
Declaring Variable-Length Array Parameters
How Functions Are Executed
Pointers as Arguments and Return Values
Inline Functions
Non-Returning Functions
Recursive Functions
Variable Numbers of Arguments
Chapter 8. Arrays
Defining Arrays
Fixed-Length Arrays
Variable-Length Arrays
Accessing Array Elements
Initializing Arrays
Writing Initialization Lists
Initializing Specific Elements
Strings
Multidimensional Arrays
Matrices
Declaring Multidimensional Arrays
Initializing Multidimensional Arrays
Arrays as Arguments of Functions
Chapter 9. Pointers
Declaring Pointers
Null Pointers
void Pointers
Initializing Pointers
Operations with Pointers
Using Pointers to Read and Modify Objects
Modifying and Comparing Pointers
Pointers and Type Qualifiers
Constant Pointers and Pointers to Constant Objects
Restricted Pointers
Pointers to Arrays and Arrays of Pointers
Array Pointers
Pointer Arrays
Pointers to Functions
Chapter 10. Structures, Unions, and Bit-Fields
Structures
Defining Structure Types
Structure Objects and typedef Names
Incomplete Structure Types
Accessing Structure Members
Initializing Structures
Initializing Specific Members
Structure Members in Memory
Flexible Structure Members
Pointers as Structure Members
Unions
Defining Union Types
Initializing Unions
Anonymous Structures and Unions
Bit-Fields
Chapter 11. Declarations
Object and Function Declarations
Examples
Storage Class Specifiers
Type Qualifiers
Declarations and Definitions
Complex Declarators
Type Names
typedef Declarations
_Static_assert Declarations
Linkage of Identifiers
External Linkage
Internal Linkage
No Linkage
Storage Duration of Objects
Static Storage Duration
Thread Storage Duration
Automatic Storage Duration
Initialization
Implicit Initialization
Explicit Initialization
Chapter 12. Dynamic Memory Management
Allocating Memory Dynamically
Characteristics of Allocated Memory
Resizing and Releasing Memory
An All-Purpose Binary Tree
Characteristics
Implementation
Generating an Empty Tree
Inserting New Data
Finding Data in the Tree
Removing Data from the Tree
Traversing a Tree
A Sample Application
Chapter 13. Input and Output
Streams
Text Streams
Binary Streams
Files
File Position
Buffers
The Standard Streams
Opening and Closing Files
Opening a File
Access Modes
Closing a File
Reading and Writing
Byte-Oriented and Wide-Oriented Streams
Error Handling
Unformatted I/O
Formatted Output
Formatted Input
Random File Access
Obtaining the Current File Position
Setting the File Access Position
Chapter 14. Multithreading
Threads
Creating Threads
Other Thread Functions
Accessing Shared Data
Mutual Exclusion
Atomic Objects
Atomic Operations
Memory Ordering
Fences
Communication Between Threads: Condition Variables
Thread-Local Objects and Thread-Specific Storage
Using Thread-Local Objects
Using Thread-Specific Storage
Chapter 15. Preprocessing Directives
Inserting the Contents of Header Files
How the Preprocessor Finds Header Files
Nested #include Directives
Defining and Using Macros
Macros Without Parameters
Macros with Parameters
Using Macros Within Macros
Macro Scope and Redefinition
Type-generic Macros
Conditional Compiling
The #if and #elif Directives
The defined Operator
The #ifdef and #ifndef Directives
Defining Line Numbers
Generating Error Messages
The #pragma Directive
The _Pragma Operator
Predefined Macros
Conditionally Defined Macros
Part II. Standard Library
Chapter 16. The Standard Headers
Using the Standard Headers
Execution Environments
Function and Macro Calls
Reserved Identifiers
Functions with Bounds-Checking
Availability
Runtime Constraints
Contents of the Standard Headers
assert.h
complex.h
ctype.h
errno.h
fenv.h
float.h
inttypes.h
iso646.h
limits.h
locale.h
math.h
setjmp.h
signal.h
stdalign.h
stdarg.h
stdatomic.h
stdbool.h
stddef.h
stdint.h
stdio.h
stdlib.h
stdnoreturn.h
string.h
tgmath.h
threads.h
time.h
uchar.h
wchar.h
wctype.h
Chapter 17. Functions at a Glance
Input and Output
Mathematical Functions
Mathematical Functions for Integer Types
Floating-Point Functions
Function-Like Macros
Pragmas for Arithmetic Operations
The Floating-Point Environment
Error Handling
Character Classification and Conversion
Character Classification
Case Mapping
String Processing
Multibyte Characters
Converting Between Numbers and Strings
Searching and Sorting
Memory Block Handling
Dynamic Memory Management
Date and Time
Process Control
Communication with the Operating System
Signals
Internationalization
Nonlocal Jumps
Multithreading (C11)
Thread Functions
Atomic Operations
Debugging
Error Messages
Chapter 18. Standard Library Functions
Part III. Basic Tools
Chapter 19. Compiling with GCC
The GNU Compiler Collection
Obtaining and Installing GCC
Compiling C Programs with GCC
Step by Step
Multiple Input Files
Dynamic Linking and Shared Object Files
Freestanding Programs
C Dialects
Compiler Warnings
Optimization
The -O Levels
The -f Flags
Floating-Point Optimization
Architecture-Specific Optimization
Why Not Optimize?
Debugging
Profiling
Option and Environment Variable Summary
Command-Line Options
Environment Variables
Chapter 20. Using make to Build C Programs
Targets, Prerequisites, and Commands
The Makefile
Rules
The Command Script
Pattern Rules
Suffix Rules
Built-In Rules
Implicit Rule Chains
Double-Colon Rules
Comments
Variables
Assignment Operators
Variables and Whitespace
Target-Specific Variable Assignments
The Automatic Variables
Other Built-In Variables
Environment Variables
Phony Targets
Other Target Attributes
Macros
Functions
Built-In Functions
User-Defined Functions
Directives
Conditionals
Includes
Other Directives
Running make
Generating Header Dependencies
Recursive make Commands
Command-Line Options
Special Targets Used as Runtime Options
GCC Options for Generating Makefile Rules
Chapter 21. Debugging C Programs with GDB
Installing GDB
A Sample Debugging Session
Symbol Information
Finding a Bug
Starting GDB
Command-Line Arguments
Command-Line Options
Initialization Files
Using GDB Commands
Command Completion
Displaying Help for Commands
Status Information
Running a Program in the Debugger
Displaying Source Code
Working with Breakpoints
Resuming Execution After a Break
Analyzing the Stack
Displaying Data
Watchpoints: Observing Operations on Variables
Analyzing Core Files in GDB
Chapter 22. Using an IDE with C
IDEs for C
The Eclipse IDE for C/C++
Installing Eclipse CDT
Running Eclipse
Perspectives and Views
Developing a C Program with Eclipse
Creating a New C Project
Editing
Compiling and Running a Program
Project Properties
Debugging a C Program in Eclipse
Starting the Debugger
Setting Breakpoints
Controlling Program Execution in the Debugger
Further Information on Eclipse
Index