4 ms·
K&R is a well written book, and is very pleasant to read. IMO, it is one of those books that everyone should read one day or the other. The main thing to watch
by ufo 7y ago
K&R is a well written book, and is very pleasant to read. IMO, it is one of those books that everyone should read one day or the other.
The main thing to watch out about it these days is that K&R is a bit carefree about the numerous ways where you can shoot yourself in the foot using C. For example, K&R famously implements strcpy as `while(dst++ = dst++);`. These days, most people would say that code is excessively terse, and that you shouldn't be using strcpy in the first place (because it can potentially overflow the dst buffer).
- einpoklum 7y agoYou meant: while ((dst++) = (src++)) I believe.
- Gibbon1 7y agowhile ((dst++) = (src++));
- billforsternz 7y agoBoth of these replies are missing the asterisks to indicate pointer indirection. Probably HN is eating each asterisk, treating it as emphasis or something. Also terse it may be, but this (assuming the missing asterisks are restored) is a good, idiomatic implementation of strcpy. Whether strcpy is good or evil is a separate discussion.