内容简介
1.C Through the Mists of Time
The Prehistory of C
Early Experiences with C
The Standard I/O Library and C Preprocessor
K&R C
The Present Day:ANSI C
It's Nice,but Is It Standard?
Translation Limits
The Structure of the ANSI C Standard
Reading the ANSI C Standard for Fun,Pleasure,and Profit
How Quiet is a"Quiet Change"?
Some Light Relief—The Implementation-Defined Effects of Pragmas...
2.It's Not a Bug,It's a Language Feature
Why Language Features Matter—The Way the Fortran Bug Really Happened!
Sins of Commission
Switches Let You Down with Fall Through
Available Hardware Is a Crayon?
Too Much Default Visibility
Sins of Mission
Overloading the Camel's Back
"Some of the Operators Have the Wrong Precedence"
The Early Bug gets() the Internet Worm
Sins of Omission
Mail Won't Go to Users with an"f"in Their Usernames
Space—The Final Frontier
A Digression into C+++ Comments
The Compiler Date Is Corrupted
Lint Should Never Have Been Separated Out
Some Light Relief—Some Features Really Are Bugs!
References
3.Unscrambling Declarations in C
Syntax Only a Compiler Could Love
How a Declaration Is Formed
A Word About structs
A Word About unions
A Word About enums
The Precedence Rule
Unscrambling C Declarations by Diagram
typedef Can Be Your Friend
Difference Between typedef int x[10]and #define x int[10]
What typedef struct foo{...foo}foo;Means
The Piece of Code that Understandeth All Parsing
Further Reading
Some Light Relief—Software to Bite the Wax Tadpole...
4.The Shocking Truth:C Arrays and Pointers Are NOT the Same!
Arrays Are NOT Pointers!
Why Doesn't My Code Work?
What's a Declaration? What's a Definition?
How Arrays and Pointers Are Accessed
What Happens When You"Define as Array/Declare as Pointer"
Match Your Declarations to the Definition
Other Differences Between Arrays and Pointers
Some Light Relief—Fun with Palindromes!
5.Thinking of Linking
Libraries,Linking,and Loading
Where the Linker Is in the Phases of Compilation
The Benefits of Dynamic Linking
Five Special Secrets of Linking with Libraries
Watch Out for Interpositioning
Generating Linker Report Files
Some Light Relief—Look Who's Talking:Challenging the Turing Test
Eliza
Eliza Meets the VP
Doctor,Meet Doctor
The Prize in Boston
Conclusions
Postscript
Further Reading
6.Poetry in Motion:Runtime Data Structures
a.out and a.out Folklore
Segments
What the OS Does with Your a.out
What the C Runtime Does with Your a.out
The Stack Segment
What Happens When a Function Gets Called:The Procedure Activation Record
The auto and static keywords
A Stack Frame Might Not Be on the Stack
Threads of Control
setjmp and longjmp
The Stack Segment Under UNIX
The Stack Segment Under MS-DOS
Helpful C Tools
Some Light Relief—Programming Puzzles at Princeton
For Advanced Students Only
7.Thanks for the Memory
The Intel 80x86 Family
The Intel 808x6 Memory Model and How It Got That Way
Virtual Memory
Cache Memory
The Data Segment and Heap
Memory Leaks
How to Check for a Memory Leak
Bus Error,Take the Train
Bus Error
Segmentation Fault
Some Light Relief—The Thing King and the Paging Game
8.Why Programmers Can't Tell Halloween from Christmas Day
The Potrzebie System of Weights and Measures
Making a Glyph from Bit Patterns
Types Changed While You Wait
Prototype Painfulness
Where Prototypes Break Down
Getting a Char Without a Carriage Return
Implementing a Finite State Machine in C
Software Is Harder than Hardware!
How and Why to Cast
Some Light Relief—The International Obfuscated C Code Competition
9.More about Arrays
When an Array Is a Pointer
Why the Confusion?
Rule 1:An"Array Name in an Expression"Is a Pointer
Rule 2:C Treats Array Subscripts as Pointer Offsets
Rule 3:An"Array Name as a Function Parameter"Is a Pointer
Why C Treats Array Parameters as Pointers
How an Array Parameter Is Referenced
Indexing a Slice
Arrays and Pointers Interchangeability Summary
C Has Multidimensional Arrays...
...But Every Other Language Calls Them"Arrays of Arrays"
How Multidimensional Arrays Break into Components
How Arrays Are Laid Out in Memory
How to Initialize Arrays
Some Light Relief—Hardware/Software Trade-Offs
10.More About Pointers
The Layout of Multidimensional Arrays
An Array of Pointers Is an"Illiffe Vector"
Using Pointers for Ragged Arrays
Passing a One-Dimensional Array to a Function
Using Pointers to Pass a Multidimensional Array to a Function
Attempt 2
Attempt 3
Attempt 4
Using Pointers to Return an Array from a Function
Using Pointers to Create and Use Dynamic Arrays
Some Light Relief—The Limitations of Program Proofs
Further Reading
11.You Know C.So C++ is Easy!
Allez-OOP!
Abstraction—Extracting Out the Essential Characteristics of a Thing
Encapsulation—Grouping Together Related Types,Data,and Functions
Showing Some Class—Giving User-Defined Types the Same Privileges as Predefined Types
Availability
Declarations
How to Call a Method
Constructors and Destructors
Inheritance—Reusing Operations that Are Already Defined
Multiple Inheritance—Deriving from Two or More Base Classes
Overloading—Having One Name for the Same Action on Different Types
How C+++ Does Operator Overloading
Input/Output in C+++
Polymorphism—Runtime Binding
Explanation
How C+++ Does Polymorphism
Fancy Pants Polymorphism
Other Corners of C+++
If I Was Going There,I Wouldn't Start from Here
It May Be Crufty,but It's the Only Game in Town
Some Light Relief—The Dead Computers Society
Some Final Light Relief—Your Certificate of Merit!
Further Reading
Appendix:Secrets of Programmer Job Interviews
Silicon Valley Programmer Interviews
How Can You Detect a Cycle in a Linked List?
What Are the Different C Increment Statements For?
How Is a Library Call Different from a System Call?
How Is a File Descriptor Different from a File Pointer?
Write Some Code to Determine if a Variable Is Signed or Not
What Is the Time Complexity of Printing the Values in a Binary Tree?
Give Me a String at Random from This File
Some Light Relief—How to Measure a Building with a Barometer
Further Reading
Index