Windows Support Tools

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Friday, 17 October 2008

C Traps and Pitfalls (Addison Wesley, 1989, English)

Posted on 03:38 by Unknown


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.

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

About the Author

Andrew Koenig is a member of the Large-Scale Programming Research Department at AT&T's Shannon Laboratory, and the Project Editor of the C++ standards committee. A programmer for more than 30 years, 15 of them in C++, he has published more than 150 articles about C++, and speaks on the topic worldwide.
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Receiving Error 'ORA-01041: internal error. hostdef extension doesn't exist.' on re-establishing a connection to Oracle.
    You can receive the error message 'Error ORA-01041: internal error. hostdef extension doesn't exist' when attempting to re-esta...
  • Google Sinks Cash into Undersea Cable
    Google has joined the Unity consortium, which will build a $300 million fiber optic cable linking the US and Japan. The 7.68 Tbps, 10,000 ki...
  • Troubleshooting the Microsoft Exchange Transport Service When It Fails to Start on an Exchange 2007 Hub Transport Server with Event ID 1032 or 1036
    Event ID: 1032 Socket Access Denied. Binding: 0.0.0.0:25. Event ID: 1036 Failed to open one or more bindings. The service will be stopped....
  • C Traps and Pitfalls (Addison Wesley, 1989, English)
    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 beha...
  • SoftMaker Office 2008 Free Full Version Download With Genuine License Key
    SoftMaker Office 2008 is reliable office productivity software that is designed for beginners and professional users. SoftMaker Office Suite...
  • Amazon Takes the Humans Out of Fulfillment With New API
    keeps adding to its Web services. Today, it is opening up an API for its Fulfillment by Amazon service, which allows online merchants to out...
  • AP Microsoft backs Icahn's bid to oust Yahoo board
    SAN FRANCISCO - Microsoft Corp. threw its weight behind investor Carl Icahn's effort to dump Yahoo Inc.'s board, saying Monday that...
  • Suba Vesak Mangallayak Weewa !!!!
    Keep your heart free from hate your mind from worry, Live simply expect little, give much Fill your life with love forget self, think of ot...
  • How to Remove Dosearches.com homepage (Virus Removal Guide)
    Dosearches.com  is a browser hijacker, which is promoted via other free downloads, and once installed it will change your browser homepage t...
  • Alcohol 120% v5 Blu-ray Burner Free Download with Registration Unlock Code
    Alcohol 120% is a CD and DVD burning, copying, backup, recording, duplication, emulation and creation software for Windows. In addition to c...

Categories

  • ISA Firewall
  • ISA Server 2006
  • Quick Tips
  • Reports
  • Tips

Blog Archive

  • ►  2013 (7)
    • ►  October (6)
    • ►  February (1)
  • ►  2012 (10)
    • ►  September (3)
    • ►  August (3)
    • ►  July (3)
    • ►  June (1)
  • ►  2011 (16)
    • ►  August (2)
    • ►  July (4)
    • ►  June (3)
    • ►  May (1)
    • ►  April (1)
    • ►  March (4)
    • ►  January (1)
  • ►  2010 (12)
    • ►  December (3)
    • ►  October (4)
    • ►  March (1)
    • ►  January (4)
  • ►  2009 (67)
    • ►  August (2)
    • ►  July (18)
    • ►  June (23)
    • ►  April (3)
    • ►  March (6)
    • ►  February (7)
    • ►  January (8)
  • ▼  2008 (319)
    • ►  December (30)
    • ►  November (43)
    • ▼  October (45)
      • Debutant Basil - a successful troubleshooter for S...
      • Microsoft launches Windows Azure - PDC 2008: Windo...
      • List of open source software packages
      • Microsoft's Biggest Hacker in China After Massive ...
      • HOT Car Show Girls
      • Symbian Targets Open Source Developers With Free D...
      • Blackberry To Launch Two New Application Marketplaces
      • Best Online Real Time Torrent Search Engine
      • Mugshot: Red Hat's open source social networking site
      • Keyboard shortcut guide - bookmark worthy
      • The Battle Progress (Updated on 18th October)
      • LTTE attack merchant ships carrying essential sup...
      • Fedora 9 beta Linux distro released
      • Web 3.0 - Semantic Web
      • Keep Up with What You are Into..........
      • OpenOffice.org 3.0 coming Monday, download it today!
      • Googleholic
      • “Professional football against Hunger” solidarity ...
      • World Food Day, 16 October 2008
      • Sri Lanka - The Leopard's Island.
      • How To Use FTP Without Installing FTP Client Software
      • VMWare Update: Two Rough Quarters
      • How to prevent the Windows Messenger from running ...
      • Complete Wireless Design (McGraw-Hill, 2008, English)
      • Hacking iPod and iTunes (ExtremeTech)
      • Software Process Quality : Management and Control
      • C Traps and Pitfalls (Addison Wesley, 1989, English)
      • Munchee "withdraws Lemon Puff"
      • Google update stomps Chrome browser bugs
      • Manage your home network better with Network Magic...
      • eBay issues gloomy forecast as tech stocks tank again
      • Google to buy GeoEye satellite imagery
      • Windows Mobile Running On iPhone is a Sonic Emotio...
      • Plunge in RIM's shares could attract takeover bid
      • General Motors and Chrysler have held merger talks...
      • Event ID: 9409 occurs every time that the Microsof...
      • MOTO Q 9h
      • India's 3G Unlikely to Happen Soon
      • Tameer to develop world's largest LED screen in ne...
      • Nokia Comes With Music officially launches October...
      • Samsung Rolls Out an 8Mpix Camera Phone: The Pixon
      • History - Motorola Makes 'Good' Buy
      • Motorola's Good(TM) Mobile Messaging Receives ATO ...
      • Microsoft: There's More to Life Than Search
      • 18 ways to be a great boss
    • ►  September (12)
    • ►  August (18)
    • ►  July (27)
    • ►  June (15)
    • ►  May (7)
    • ►  April (55)
    • ►  March (65)
    • ►  January (2)
  • ►  2007 (10)
    • ►  December (2)
    • ►  November (8)
Powered by Blogger.

About Me

Unknown
View my complete profile