Re:C Traps and Pitfalls (1988) [pdf]
by bch on Friday June 19, 2015 @07:31PM
(#9748289)
> 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."
Re:C Traps and Pitfalls (1988) [pdf]
by McUsr on Friday June 19, 2015 @08:39PM
(#9748461)
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]
Re:C Traps and Pitfalls (1988) [pdf]
by ouah on Saturday June 20, 2015 @11:19AM
(#9750168)
"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.
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."
The "even a cast" part is wrong. The usual arithmetic conversions (including the integer promotion) is not done with the cast operation in C.
Some of the advice does seem odd to me, such as the warning regarding bitwise vs. logical operators.