Even C experts come across problems that require days ofdebugging to fix. This book helps to prevent such problems byshowing how C programmers get themselves into trouble. Each ofthe book's many examples has trapped a professional programmer.
In addition to its examples, C Traps and Pitfalls offers adviceon:
- avoiding off-by-one errors
- understanding and constructing function declarations
- understanding the subtle relationship between pointers andarrays
Distilled from the author's experience over a decade ofprogramming in C, this book is an ideal resource for anyone,novice or expert, who has ever written a C program.
0201179288B04062001Tools that are comfortable after experience are often more difficult to learn at first than those that feel right immediately. Student pilots start out overcontrolling, turning first flights into roller-coaster rides, until they learn how light a touch flying really requires. Training wheels on a bicycle make it easier for a novice to ride, but get in the way after that.
So it is also with programming languages. Every programming language has aspects that are most likely to cause trouble for people not yet thoroughly familiar with them. These aspects vary from one language to another, but are surprisingly constant from one programmer to another. Thus the idea of collecting them.
My first effort to collect such problems was in 1977, when I gave a talk calledPL/I Traps and Pitfallsat the SHARE (IBM mainframe users' group) meeting in Washington, DC. That was shortly after I moved from Columbia University, where people used PL/I heavily, to AT&T Bell Laboratories, where people use C heavily. The decade that followed gave me ample experience in how C programmers (including me) can get themselves into trouble if they're not certain of what they're doing.
I started collecting C problems in 1985 and published the collection as an internal paper at the end of that year. The response astonished me: more than 2,000 people requested copies of the paper from the Bell Labs library. That convinced me to expand the paper into this book.
What This Book Is
C Traps And Pitfallsaims to encourage defensive programming by showing how other people, even experienced professionals, have gotten themselves into trouble. These mistakes are generally easy to avoid once seen and understood, so the emphasis is on specific examples rather than generalities.
This book belongs on your shelf if you are using C at all seriously, even if you are an expert: many of the professional C programmers who saw early drafts said things like "that bug bit me just last week!" If you are teaching a course that uses C, it belongs at the top of your supplementary reading list.
This book is not a criticism of C. Programmers can get themselves into trouble in any language. I have tried here to distill a decade of C experience into a compact form in the hope that you, the reader, will be able to avoid some of the stupid mistakes I've made and seen others make.
This book is not a cookbook. Errors cannot be avoided by recipe. If they could, we could eliminate automobile accidents by plastering the countryside with"Drive Carefully"signs! People learn most effectively through experience--their own or someone else's. Merely understanding how a particular kind of mistake is possible is a big step on the way to avoiding it in the future.
This book is not intended
<< less