Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
C Traps and Pitfalls (1988) [pdf] (literateprogramming.com)
51 points by aaronchall on June 19, 2015 | hide | past | favorite | 7 comments


The book of the same name is a decent third book on C: K&R or some other intro, Expert C Programming, then this.


> The book of the same name is a decent third book on C: K&R or some other intro, Expert C Programming, then this.

For the curious, this paper _is_ the the basis for the aforementioned book...

"This paper, greatly expanded, is the basis for the book C Traps and Pitfalls (Addison-Wesley, 1989, ISBN 0–201–17928–8); interested readers may wish to refer there as well."


Andrew Koenig, the author of this paper/book, is also co-author of Accellerated C++, which I can whole heartedly recommend. [Addison Wesley ISBN-10: 0-201-70353-X]


+32


"Incidentally, it is a common misconception that if c is a character variable, one can obtain the unsigned integer equivalent of c by writing (unsigned) c. This fails because a char quantity is converted to int before any operator is applied to it, even a cast. Thus c is converted first to a signed integer and then to an unsigned integer, with possibly unexpected results."

The "even a cast" part is wrong. The usual arithmetic conversions (including the integer promotion) is not done with the cast operation in C.


Lots of code in there is deprecated. Don't use it.


Well, that is kind of to be expected, the paper is nearly thirty years old. It is still an interesting read, though, if one uses C a lot.

Some of the advice does seem odd to me, such as the warning regarding bitwise vs. logical operators.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: