Skip to content
HomeVideosBooks
AllTopicsTrends
BlogsPodcasts
HistoryListsWatch laterLiked videosFollowing

The videos, books, blogs and podcasts Hacker News keeps recommending, all in one place.

VideosBooksBlogsPodcastsAboutPrivacySettings

Data from Hacker News, HackerTube, HackerBooks, HackerBlogs and Open Library. Credits · Not affiliated with Y Combinator.

HomeVideosBooksBlogsPodcasts
Ctrl K
    Cover of C Traps and Pitfalls

    C Traps and Pitfalls

    Andrew Koenig · 1989

    Even experienced C programmers can get themselves into trouble if they're not certain of what they're doing. Each of the book's many examples has trapped a professional programmer. 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. Covers lexical, syntactic, and semantic pitfalls, linking and library problems, preprocessor, and portability pitfalls.

    Programming
    Open LibraryAmazon
    Stats for nerds
    19recommend
    37mentions
    24people
    2009–2025years
    81% recommend16% neutral3% critical

    Mentions per year

    200920112013201520172019202120232025

    What Hacker News says

    1. pjc50Apr 2025
      Could you give an example of "clever" (bad) vs "simple" (good)?

      In my experience C has a lot of simple grammar, a commonly-held simple (wrong) execution model, and a lot more complexity lurking underneath where it can't be so easily seen.

      (One of my formative learning books was https://en.wikipedia.org/wiki/C_Traps_and_Pitfalls , valid in the 90s and mostly still valid today)

      thread
    2. pjc50Nov 2022
      The elderly "C Traps and Pitfalls" http://www.literateprogramming.com/ctraps.pdf was an extremely helpful book when I was learning C, although I don't know how well it's held up.
      thread
    3. harry8Jul 2022
      Let's be controversial. K&R is lovely, I learned from it, everything good everyone says about it is true and K & R and both beautiful, sexy, clever, kind and wonderous men.

      If you are learning programming (and who among us isn't?), the code examples stink to high heaven. No really. Don't program like that! K&R didn't! If you're learning programming and C it will teach you a bunch of really bad habits /because/ it is a book for experienced programmers with fully developed taste and the examples were designed to illustrate a particular facet of the language as pithily as possible. It's great for that.

      I realize any criticism of the sacred texts will result in inspiring revulsion and possibly bile among those who think of such things as above criticism and any commentary is about the shortcomings of the commentator not the holy book but there it is... It's 2022 and I'm old enough to take it. ;-)

      Alistair Moffat "Programming, Problem Solving and Abstraction" is one I found that seems better to learn C programming. Maybe other people have better recommendations than that..?

      Separate to that "The C Puzzle Book" is superb when you're learning to really thoroughly understand pointers, arrays and so on. Koenig's "C Traps and Pitfalls" isn't bad for some of the dark corners.

      thread
    4. rramadassDec 2021
      If you don't know C at all, hunt down a old book called The C Primer by Hancock and Krieger. It is the best introduction to C for absolute noobs. It was based on teaching notes used at Bell Labs itself and is quite easy to read and follow (i owe my career to having read this book when i was a noob). You can then move on to K&R.

      Next you should checkout Data Structures and Program Design in C by Kruse, Tondo et al. This book teaches Algorithms/Data Structures but using good structuring techniques in C. Follow up with Sedgewick's books.

      To learn about C and Low-level details there is nothing better than Computer Systems: A Programmer's Perspective by Bryant and O'Hallaron.

      Finally, to learn about the dark corners of C checkout C Traps and Pitfalls by Andrew Koenig and Expert C Programming: Deep C Secrets by Peter Van Der Linden.

      thread
    5. gradschoolJul 2021
      This paper [1] should be required reading for all would-be C replacement authors who don't want to follow in the footsteps of their unsuccessful predecessors. As for my two cents, the design of modern programming languages seems to be based on a premise of distrust for the programmer, but the designers appear to have forgotten that the distrust goes both ways. In [2], an old book about C programming, readers are reminded that rarely used language features incur the risk of the compiler writer not having implemented them correctly. It's unlikely that any fancy new feature would make me prefer your C replacement because I don't even use all of the features of C most of the time.

      That being said, if you're crazy enough to write a C replacement in the first place, then maybe you'll be crazy enough to incorporate my crazy suggestion for function specialization. In functional languages, given a function f(w,x,y,z) with many parameters, it's straightforward to define another function g(a,b) with fewer parameters as being equal to f(H,b,a,K), a more general function specialized by fixed constants for some of the parameters and arbitrary permutations of the others. I'd like to be able to express the transformation that takes a pointer to the general function f as input and returns a pointer to the specialized function g, such that the pointer to g can be used in the same context as any other pointer to a function of that arity and type defined the normal way. I'd like it to be possible in a library written be me operating on user-supplied pointers to functions not known in advance, I'd like to avoid workarounds such as global static variables or thread-specific storage, and I'd like you to convince me that your implementation of this feature is too simple to be wrong.

      [1] "Some Were Meant for C" by Stephen Kell https://doi.org/10.1145/3133850.3133867

      [2] "C Traps and Pitfalls" by Andrew Koenig

      edit: typo

      thread
    6. cratermoonMar 2021
      My favorite books about languages are the ones that point out where the language is ambiguous or otherwise has surprising, e.g C Traps and Pitfalls and Java Puzzlers: Traps, Pitfalls, and Corner Cases, . It would be great if there were programming languages with no surprises, but I don't think that it's possible. Every language has to compromise on some things in order to solve the problems it was designed for.
      thread

    Related

    Cover of C interfaces and implementations
    2008–2026

    C interfaces and implementations

    David R. Hanson
    46 recommend · 114
    Cover of The Standard C Library
    2009–2026

    The Standard C Library

    P. J. Plauger
    17 recommend · 29
    Cover of Compiler construction for digital computers
    2015–2026

    Compiler construction for digital computers

    David Gries
    1 recommend · 7
    Cover of Embedded C
    2010–2024

    Embedded C

    Michael J. Pont
    1 recommend · 3
    Cover of The C puzzle book
    2009–2022

    The C puzzle book

    Alan R. Feuer
    10 recommend · 17
    Cover of Expert C programming!
    2008–2026

    Expert C programming!

    Peter Van der Linden
    88 recommend · 150
    Cover of The C Programming Language
    2007–2026

    The C Programming Language

    Brian W. Kernighan
    246 recommend · 604
    Cover of Writing efficient programs
    2010–2024

    Writing efficient programs

    Jon Louis Bentley
    9 recommend · 24