Jump to ratings and reviews
Rate this book

C Traps and Pitfalls

Rate this book
Buyer name crossed out on second page.

160 pages, Paperback

First published January 1, 1989

8 people are currently reading
122 people want to read

About the author

Andrew Koenig

11 books9 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
30 (34%)
4 stars
39 (44%)
3 stars
15 (17%)
2 stars
4 (4%)
1 star
0 (0%)
Displaying 1 - 10 of 10 reviews
Profile Image for David Lindelof.
44 reviews19 followers
August 17, 2011
Very good book, possible my third best book on C after K&R and 'Expert C Programming'.

This is not simply a list of puzzles, this book discusses real problems that one encounters when writing C code. I thoroughly enjoyed this book.
Profile Image for G. Branden.
131 reviews56 followers
May 2, 2016
Good stuff, sound advice, and despite its age (on the cusp of C89), still mostly relevant. (The most dated thing is an appendix which covers varargs.h in addition to stdarg.h.)

Comes with exercises and solutions to same. Loaded with great stuff, concisely worded rules, and head-slappingly good war stories.

An excellent second book on C; wish I'd had it way back in my first C programming course.

Written with character and verve. I'll illustrate one of my favorite quotes with a code example closely adapted from the book, in a section on ensuring that your output buffers are flushed (so that error messages don't go into the bit bucket).


/* compiles cleanly with -Wall on GCC 5.3.0 */

‪#‎include‬
#include

int main(int argc, char *argv[]) {
int c;

setbuf(stdout, malloc(BUFSIZ));

while ((c = getchar()) != EOF)
putchar(c);

return 0;
}


"If you like sleazy programming techniques, notice that there is no need here to check if malloc succeeded. If malloc fails, it will return a null pointer. This is an acceptable second argument to setbuf; it requests that stdout be unbuffered."

(Sorry about the indentation; I tried <pre>, but Goodreads does not respect my whitespace.)
208 reviews46 followers
June 27, 2012
The book was written before the ANSI standard was ratified, so many of the traps and pitfalls covered stem from the interaction between K&R code and Standard C. However, other traps and pitfalls remain relevant (getchar() returns an int, not a char; the preprocessor doesn't always do what you think; operator precedence can cause trouble; etc.).

I found the narrative style enjoyable, and learned a few things along the way. I even enjoyed reading the history behind traps that are no longer relevant; several of those examples were outright entertaining.
Profile Image for Nick Black.
Author 2 books879 followers
November 28, 2008
Predates ANSI/ISO C90 and is thus pretty useless. I'm sure it was a valuable book back in the K&R1 days, but don't bother with it now.
Profile Image for Catbaron.
69 reviews
April 30, 2022
并不高深,但是读过之后会有收获。而且厚度让人赏心悦目不至于望而生畏。语言教材中的散文。
4 reviews
August 27, 2016
from lexical to syntactic to semantic, this thread is a tour through the classic compiler process;
from linkage to lib func to preprocess, this thread completes an integral program to run;
topics like portability, printf family, and varargs broaden and deepen our views.
Especially, The detailed answers are valuable treasures.

1 star lost because of its short length
1 review
February 25, 2016
So far, I have read K&R This book has a few gems on the underlying workings of the C language, however, the bulk of this book isn't that helpful. It goes over many (what I deem) obvious "traps and pitfalls" of C. However, there seems to be little that this book covers that "Expert C Programming: Deep C Secrets" by Peter Van Linden does not thoroughly explain.
Profile Image for Miguel Ángel.
2 reviews1 follower
October 30, 2016
Definitely it had to be a must in the shelf of every software developer back in the 80's, but today it is very outdated. Nevertheless, it contains a lot of valuable information that could be useful, even if you are programming in C99/C11 and not some kind of pre-ANSI C in a DEC PDP-11.
Profile Image for Kartik Singhal.
68 reviews73 followers
August 6, 2012
Highly recommended for those willing to know the ins and outs of C. One less star for no update in last twenty years.
Displaying 1 - 10 of 10 reviews

Can't find what you're looking for?

Get help and learn more about the design.