Programming Books C Java PHP Python Learn more Browse Programming Books
Qty:1
  • List Price: $39.99
  • Save: $10.29 (26%)
FREE Shipping on orders over $35.
Only 6 left in stock (more on the way).
Ships from and sold by Amazon.com.
Gift-wrap available.
FREE Shipping on orders over $35.
Condition: Used: Good
Comment: The item shows wear from consistent use, but it remains in good condition and works perfectly. It may be marked, have identifying markings on it, or show other signs of previous use.
Access codes and supplements are not guaranteed with used items.
Have one to sell? Sell on Amazon
Flip to back Flip to front
Listen Playing... Paused   You're listening to a sample of the Audible audio edition.
Learn more
See this image

C Traps and Pitfalls Paperback – January 11, 1989

ISBN-13: 978-0201179286 ISBN-10: 0201179288 Edition: 1st

Buy New
Price: $29.70
37 New from $18.00 43 Used from $0.01 1 Collectible from $25.00
Amazon Price New from Used from
Paperback
"Please retry"
$29.70
$18.00 $0.01
Free Two-Day Shipping for College Students with Amazon Student Free%20Two-Day%20Shipping%20for%20College%20Students%20with%20Amazon%20Student


Frequently Bought Together

C Traps and Pitfalls + Expert C Programming: Deep C Secrets + The C Puzzle Book
Price for all three: $84.37

Buy the selected items together
NO_CONTENT_IN_FEATURE

Hero Quick Promo
Year-End Kindle Daily Deals
Load your library with great books for $2.99 or less each, today only. Learn more

Product Details

  • Paperback: 160 pages
  • Publisher: Addison-Wesley Professional; 1 edition (January 11, 1989)
  • Language: English
  • ISBN-10: 0201179288
  • ISBN-13: 978-0201179286
  • Product Dimensions: 5.9 x 0.5 x 8.9 inches
  • Shipping Weight: 8.5 ounces (View shipping rates and policies)
  • Average Customer Review: 4.0 out of 5 stars  See all reviews (20 customer reviews)
  • Amazon Best Sellers Rank: #917,901 in Books (See Top 100 in Books)

Editorial Reviews

Amazon.com Review

C Traps and Pitfalls teaches how the peculiarities of the C language make it easy for the intended behavior of a program and the actual behavior of a program to differ. The book's experienced author, Koenig, follows up with examples and helpful advice on many of these "pitfalls." Each chapter includes exercises for contemplation with accompanying discussions at the end of the book.

From the Inside Flap

Tools 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 called PL/I Traps and Pitfalls at 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 Pitfalls aims 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. What This Book Is Not

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 to teach you how to program in C (see Kernighan and Ritchie: The C Programming Language, Second Edition, Prentice-Hall 1988), nor is it a reference manual (see Harbison and Steele: C: A Reference Manual, Second Edition, Prentice-Hall, 1987). It does not mention algorithms or data structures (see Van Wyk: Data Structures And C Programs, Addison-Wesley 1988), and only briefly discusses portability (see Horton: How To Write Portable Programs In C., Prentice-Hall 1989) and operating system interfaces (see Kernighan and Pike: The Unix Programming Environment, Prentice-Hall 1984). The problems mentioned are real, although often shortened (for a collection of composed C problems see Feuer: The C Puzzle Book, Prentice-Hall 1982). It is neither a dictionary nor an encyclopedia; I have kept it short to encourage you to read it all. Your Name in Lights

I'm sure I've missed some pitfalls. If you find one I've missed, please contact me via Addison-Wesley. I may well include your discovery, with an acknowledgement, in a future edition. A Word about ANSI C

As I write this, the ANSI C standard is not yet final. It is technically incorrect to refer to "ANSI C" until the ANSI committee finishes its work. In practice, though, the ANSI standard is far enough along that nothing I say about ANSI C is likely to change. C compilers are already available that implement many of the significant improvements contemplated by the ANSI committee.

Don't worry if your C implementation does not support the ANSI function syntax mentioned here: it is easy enough to understand the parts of the examples where it matters, and you can fall into the traps described there regardless of what version of C you use. Acknowledgements

A collection like this could not possibly have been made in isolation. People who have pointed out particular pitfalls include Steve Bellovin, Mark Brader, Luca Cardelli, Larry Cipriani, Guy Harris and Steve Johnson, Phil Karn, Dave Kristol, George W. Leach, Doug McIlroy, Barbara Moo, Rob Pike, Jim Reeds, Dennis Ritchie, Janet Sirkis, Richard Stevens, Bjarne Stroustrup, Ephraim Vishnaic, and one contributor who wishes to remain anonymous. For brevity, I've mentioned only the first person to report any particular problem to me. Of course, I doubt any of the people I've mentioned actually invented the programming errors they pointed out to me, and if they did I doubt they'd admit it! I know I've made many of them myself too, some several times.

Useful editorial suggestions came from Steve Bellovin, Jim Coplien, Marc Donner, Jon Forrest, Brian Kernighan, Doug McIlroy, Barbara Moo, Rob Murray, Bob Richton, Dennis Ritchie, Jonathan Shapiro, and several anonymous reviewers. Lee McMahon and Ed Sitar pointed out what would otherwise have ben embarrassing typographical errors in early drafts of the manuscript. Dave Prosser clarified many fine points of ANSI C for me. Brian Kernighan supplied invaluable typesetting tools and assistance.

It has been a delight to work with the people at Addison-Wesley, including Jim DeWolf, Mary Dyer, Lorraine Ferrier, Katherine Harutunian, Marshall Henrichs, Debbie Lafferty, Keith Wollman, and Helen Wythe. I'm sure they've gained from the aid of others whom I haven't met.

I am particularly grateful to the enlightened managers at AT&T Bell Laboratories who made it possible for me to write this book at all, including Steve Chappell, Bob Factor, Wayne Hunt, Rob Murray, Will Smith, Dan Stanzione, and Eric Sumner.

The title of this book was suggested by Robert Sheckley's science-fiction anthology The People Trap and Other Pitfalls, Snares, Devices and Delusions (as well as Two Sniggles and a Contrivance), published by Dell Books in 1968. 0201179288P04062001


More About the Author

Discover books, learn about writers, read author blogs, and more.

Customer Reviews

This is a very small book but clarifies a lot of internals of programming language.
Mihir
There are many doorstops that call themselves C programming reference books, including the one that I used as an undergrad.
Lance C. Hibbeler
If you program in C or C++, you must read this book if you want to consider yourself a superior programmer.
From_Plano_TX

Most Helpful Customer Reviews

20 of 21 people found the following review helpful By From_Plano_TX on December 27, 1999
Format: Paperback
If you program in C or C++, you must read this book if you want to consider yourself a superior programmer. If you are a college student, definitely read this book. Koenig fills in a lot of gaps left by authors of introductory books on C or C++. Why do I mention C++? Because C++ is far more than just objects and classes. The lower level implementation of functions is still basically C programming. He includes chapters on linkage, the preprocessor, and portability. It is a short book that is definitely worth reading.
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
19 of 20 people found the following review helpful By A Customer on May 13, 1997
Format: Paperback
This is among the five "must have" books on the astute C programmer's bookshelf. Actually, it spends little time on the shelf since one refers to it time and time again. This slim volume packs a lot of information about those "gotchas" that still "getcha" (when you least expect it). The Introduction is "Chapter 0", your first hint that Koenig knows and respects the subject. His treatment of unscrambling complex declarations is especially good.

Why a 9 instead of a 10? Simple. Andy: please release a new version! The ANSI/ISO standard is almost ten years old. :)
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
14 of 16 people found the following review helpful By scott-gamer on November 21, 2008
Format: Paperback
I'd recommend this book for novice C programmers, people with two or less years of coding experience. However, this 1989 book focuses on pre-ANSI C, so the novice would need to be guided by someone that knows the history of C. Some of his statements are false when applied to ANSI C with prototypes (e.g., p.139, it _is_ possible to pass a char argument, if there is a function prototype). I read through and did the problems in this slim book in about three hours. It does have a few nuggets of value, and introduced me to a bug I'd not seen before, the reverse of the "= for ==" bug:
while( (x == fgetc(f)) != EOF )
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
4 of 4 people found the following review helpful By talkaboutquality VINE VOICE on December 4, 2006
Format: Paperback
If you have to write in C, then yes, it is still worth reading a good, short book about C even if it was written in 1989. It can get a bit boring to read the details of selected problems and solutions in C cover-to-cover, but it's only 100 pages. An experienced C programmer will probably know many of these answers, and can skim over what's not new. But if you hit even one pitfall which is new to you, or which you have not made the effort to avoid, then the book was worth it. The bonus is the last chapter, "Advice". It's only a few pages, and is followed by answers to exercises. But I think it has more meaning if you do leave it until the end of your reading.

(One caveat: Since Koenig was writing before long variable names were common, his examples do not serve as best practice for modern variable-naming in an IDE with auto-complete.)
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
13 of 17 people found the following review helpful By A Customer on July 23, 1999
Format: Paperback
Along with Holub's 'The C Companion', this is one of the few programming books that I've read in 13 years of C programming that talks about real programming issues instead of simply rehashing what a for loop is. A must read for C programmers.
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
2 of 2 people found the following review helpful By Lance C. Hibbeler on December 22, 2007
Format: Paperback Verified Purchase
To preface my review, I learned how to program in C four years ago as an undergraduate engineer, but didn't really get into it until I started my graduate studies about a year and a half ago. I would describe myself as a very competent C programmer, but by no means an expert.

There are many doorstops that call themselves C programming reference books, including the one that I used as an undergrad. This book should be on any C programmer's shelf as the first go-to guide during debuggings. I found this book very helpful, despite the fact that it is almost 20 years old (pre-ANSI C). It highlights many issues that I have pulled my hair out trying to find and fix in the programs I have written over the years, and also some new bugs that have yet to bite me. Perhaps my original C text wasn't the best to begin with, but the proper usage of many aspects of C have been explained to me with this text, such as safely writing macros and using the static keyword (especially with multiple-file programs), just to name a few. He also explains (in an appendix) using the library variable-argument functions, which I have been trying to get working without any success...until now.

This is a small book, and I read a chapter or two every night for a few days. Programming isn't exactly page-turning literature, but the author makes his point clearly and concisely. I highly recommend this book for students and practicing programmers alike.
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
By D. Spargur on June 21, 2014
Format: Paperback Verified Purchase
I bought because it was required for a class, but I don't plan to unload it afterwards - has a lot of good tips.
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again
Format: Paperback Verified Purchase
Some of the lessons are a lot less applicable now, but the entirety of the book is an interesting glance into history and explains many of the reasons C is the way it is!
Comment Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again

Most Recent Customer Reviews


What Other Items Do Customers Buy After Viewing This Item?