Written for experienced C programmers who want to quickly pick up some of the insights and techniques of experts and master the fine arts of ANSI C, this volume passes on the wisdom of a highly experienced C compiler writer and his colleagues to help programmers reach new heights, and avoid common software pitfalls along the way. Using an original approach and a humorous style that makes deep knowledge both easy and accessible, it gathers into one place, tips, hints, shortcuts, guidelines, ideas, idioms, heuristics, tools, anecdotes, C folklore, and techniques that are often penciled in margins and on backs of papers by those working in the programming trenches―working on many different kinds of projects, over many, many years. KEY TOPICS: Each chapter is divided into self-contained sections. Includes extended discussions of major topics such as declarations and arrays/pointers; offers a great many hints and mnemonics; covers topics that many C programmers find confusing; and features one of the best introductions to C++, and the rationale behind it. Throughout, technical details are interspersed with many true stories of how C programming works in practice, and each chapter ends with an amusing C story or piece of software folklore. MARKET: For software engineers and computer programmers who are writing, developing, testing, debugging software on either IBM PCs or Unix systems. Intro......Page 2 The $20 Million Bug......Page 3 Tuning File Systems......Page 4 Prehistory of C......Page 7 Early Experiences with C......Page 10 Standard IO Library & C Preprocessor......Page 11 K&R C......Page 14 ANSI C......Page 16 Is it Standard......Page 18 Translation Limits......Page 20 Structure of the ANSI C Standard......Page 21 Reading the ANSI C Standard......Page 25 How Quiet is a "Quiet Change"......Page 28 Implementation Effects of Pragmas......Page 32 2 It's Not a Bug, It's Language Feature......Page 33 Why Language Features matter......Page 34 Switches let you down with fall through......Page 35 Available Hardware is a Crayon......Page 41 Too much default Visibility......Page 42 Overloading the Camel's Back......Page 43 Operators have the wrong Precedence......Page 45 The early Bug gets() the Internet Worm......Page 49 Sins of Omission......Page 51 Space......Page 53 Digression into C++ Comments......Page 54 The Compiler Date is corrupted......Page 55 Lint should never have been separated out......Page 58 Some Features really are Bugs!......Page 59 3 Unscrambling Declarations in C......Page 60 Syntax only a Compiler could love......Page 62 How a Declaration is formed......Page 63 structs......Page 65 unions......Page 67 The Precedence Rule......Page 69 Unscrambling C Declarations by Diagram......Page 71 typedef can be your Friend......Page 73 typedef struct foo { ... foo; } foo;......Page 75 The Piece of Code that understandeth all Parsing......Page 78 Software to bite the Wax Tadpole......Page 80 Why doesn't my Code work......Page 86 Declaration? Definition?......Page 87 How Arrays & Pointers are accessed......Page 88 Define as Pointer / Reference as Array......Page 90 Match Declarations to the Definition......Page 91 Other Differences btw Arrays & Pointers......Page 92 Fun with Palindromes!......Page 93 Libraries, Linking & Loading......Page 96 Benefits of Dynamic Linking......Page 100 5 Special Secrets of Linking with Libraries......Page 104 Watch out for Interpositioning......Page 108 Generating Linker Report Files......Page 113 Challenging the Turing Test......Page 114 Eliza......Page 115 6 Runtime Data Structures......Page 119 a.out & a.out Folklore......Page 120 Segments......Page 121 What the OS does with your a.out......Page 124 What the C Runtime does with Your a.out......Page 126 The Procedure Activation Record......Page 128 The auto & static keywords......Page 131 setjmp & longjmp......Page 132 Helpful C Tools......Page 135 Programming Puzzles at CMU......Page 139 For Advanced Students only......Page 140 7 Thanks for the Memory......Page 141 Intel 80x86 Family......Page 142 Intel 80x86 Memory Model......Page 145 Virtual Memory......Page 149 Cache Memory......Page 153 The Data Segment & Heap......Page 156 Memory Leaks......Page 158 How to check for a Memory Leak......Page 159 Bus Error, take the Train......Page 162 The Thing King & the Paging Game......Page 169 8 Tell Halloween from Christmas......Page 173 The Potrzebie System of Weights & Measures......Page 174 Making a Glyph from Bit Patterns......Page 175 Types changed while you wait......Page 176 Implementing Finite State Machine in C......Page 188 Software is harder than Hardware!......Page 189 How & why to cast......Page 192 The International obfuscated C Code Competition......Page 194 9 More about Arrays......Page 205 When Array IS Pointer......Page 206 Why the Confusion......Page 207 Rule 2 C treats Array Subscripts as Pointer Offsets......Page 209 Why C treats Array Parameters as Pointers......Page 211 How Array Parameter is referenced......Page 212 Indexing a Slice......Page 215 Arrays of Arrays......Page 216 How Multidimensional Arrays break into Components......Page 218 How Arrays are laid out in Memory......Page 219 How to initialize Arrays......Page 220 Hardware/Software Trade-offs......Page 222 Layout of Multidimensional Arrays......Page 224 Array of Pointers is "Iliffe Vector"......Page 225 Pointers for Ragged Arrays......Page 228 For Advanced Students only......Page 230 Using Pointers to pass Multidimensional Array to Function......Page 231 Using Pointers to return Array from Function......Page 235 Using Pointers to create & use Dynamic Arrays......Page 237 The Limitations of Program Proofs......Page 242 Reading......Page 245 Allez-OOP!......Page 246 Abstraction......Page 248 Encapsulation......Page 249 User Types......Page 250 Availability......Page 251 Declarations......Page 252 How to call a Method......Page 254 Constructors & Destructors......Page 255 Inheritance......Page 256 Multiple Inheritance......Page 260 C++ Operator Overloading......Page 261 IO in C++......Page 262 Polymorphism......Page 263 Explanation......Page 265 Fancy Pants Polymorphism......Page 266 Other Corners of C++......Page 267 I wouldn't start from here......Page 269 The only Game in Town......Page 272 The Dead Computers Society......Page 275 Programmer Job Interviews......Page 277 How Can You Detect a Cycle in a Linked List?......Page 278 What Are the Different C Increment Statements For?......Page 280 How Is a Library Call Different from a System Call?......Page 282 Write Some Code to Determine if a Variable Is Signed or Not......Page 284 What Is the Time Complexity of Printing the Values in a Binary Tree?......Page 285 Some Light Relief—How to Measure a Building with a Barometer......Page 286 Reading......Page 289
This is a very different book on the C language! In an easy, conversational style, Peter van der Linden, of Sun's compiler and OS kernel group, presents dozens of astonishing examples drawn from practical experience, including:
- Software that blew up the space probe to Venus
- The C bug that shut down the entire AT&T phone system
- C programmer job interview secrets
- Why programmers can't tell Halloween from Christmas day
- The C code for a complete BASIC interpreter
Expert C Programming reveals the coding techniques used by the best C programmers. It relates C to other languages, and includes an introduction to C++ that can be understood by an programmer without weeks of mind-bending study. Covering both the IBM PC and UNIX systems, it is an entertaining and educational romp through C showing how experts really use it. Expert C Programming is a must read for anyone who wants to learn more about the implementation, practical use, and folklore of C.
"Not just clearly written, but fun to read. The tone and style of this text should make this a popular book with professional programmers. However, the tone of this book will make it very popular with undergraduates. Appendix A alone would make the purchase of this book a must. It's filled with great advice."
—Professor Jack Beidler, Chairman, Department of Computer Science, University of Scranton
"So that's why extern char *cp isn't the same as extern char cp. I knew that it didn't work despite their superficial equivalence, but I didn't know why. I also love the job interview test questions on C."
—David S. Platt, Rolling Thunder Computing
"In Expert C Programming, Peter van der Linden combines C language expertise and a subtle sense of humor to deliver a C programming book that stands out from the pack. In a genre too often known for windy, lifeless prose, van der Linden's crisp language, tongue-in-cheek attitude, and real-world examples engage and instruct."
—John Barry, author of Sunburst, Technobabble, and other books
Most C books are filled with dry and boring prose about C syntaxes, libraries, and pointers... until now. Written much like Libe's Life With UNIX book, van der Linden combines comical anecdotes as well as instructional programming tips on C. Informative footnotes on software dogmas, programming challenges, and handy heuristics are give facts, tips and tricks on C programming. Chapter eleven will digress a little into C++ language characteristics such as polymorphism, declarations, inheritances and multiple inheritances. The differences between "K & R" C and ANSI C are deftly explained as well as virtual and cache memory, stack segments under different platforms, and C arrays and pointers. A couple of anecdotes explain the $20 million bug held in the asynchronous I/O library, and the 1962 forced explosion of a $12 million rocket because of an error in programming. At the completion of this book you will not get a cookie, but you will get a Certificate of Merit (which is at the end of chapter 11) for burning the midnight oil studying this stuff. Don't be shocked if you find yourself wanting to read this book instead of having to read it!
"This is a very different book on the C language! In an easy, conversational style, Peter van der Linden, of Sun's compiler and OS kernel group, presents dozens of astonishing examples drawn from practical experience, including software that blew up the space probe to Venus; the C bug that shut down the entire AT & T phone system; C programmer job interview secrets; why programmers can't tell Halloween from Christmas day; and the C code for a complete BASIC interpreter." "Expert C Programming reveals the coding techniques used by the best C programmers. It relates C to other languages, and includes an introduction to C++ that can be understood by any programmer without weeks of mind-bending study. Covering both the IBM PC and UNIX systems, it is an entertaining and educational romp through C showing how experts really use it. Expert C Programming is a must read for anyone who wants to learn more about the implementation, practical use, and folklore of C."--Jacket Written for experienced C programmers who want to pick up some of techniques of experts and master the fine arts of ANSI C, this book helps programmers avoid common software pitfalls. It gathers into one place, tips, hints, shortcuts, guidelines, ideas, idioms, heuristics, tools, anecdotes, C folklore, and techniques. This book is for the knowledgeable C programmer, this is a second book that gives the C programmers advanced tips and tricks. This book will help the C programmer reach new heights as a professional. Organized to make it easy for the reader to scan to sections that are relevant to their immediate needs.