News for hackers. Stuff that matters.
Re:Modern C, Second Edition by sys_64738 on Wednesday September 18, 2019 @02:15PM (#21008297)
Do people still use K&R these days?
Re:Modern C, Second Edition by saagarjha on Wednesday September 18, 2019 @05:23PM (#21010374)
I did. It’s short, clear, well written and I found it an excellent introduction to C. I’d recommend it if you read it alongside some more modern supplements.
Re:Modern C, Second Edition by arawde on Wednesday September 18, 2019 @02:42PM (#21008579)
I can't speak for everyone, but I read K&R 4 years ago to supplement some of my classes in universtiy
Re:Modern C, Second Edition by codemonkeymike on Wednesday September 18, 2019 @05:10PM (#21010246)
Used it in college about 8 years ago. Can't say I'd do the same today, but back at that time it made some sense as college programming classes were teaching more than just practical programming knowledge.
Re:Modern C, Second Edition by earenndil on Wednesday September 18, 2019 @05:05PM (#21010189)
Yes, it's a pretty good book. Not sure what the siblings are on about.
Re:Modern C, Second Edition by dlp211 on Wednesday September 18, 2019 @04:24PM (#21009714)
Yes, but that doesn't make it a good idea.
Re:Modern C, Second Edition by wyldfire on Wednesday September 18, 2019 @07:50PM (#21011788)
I have it on the bookshelf but haven't consulted it for many years.

Zed Shaw is sometimes a bit controversial but he wrote a "learn c the hard way" (or something similar) that aims to obsolete K&R.

Re:Modern C, Second Edition by big_chungus on Wednesday September 18, 2019 @02:42PM (#21008578)
That's what I used first. I did a lot more study, but I think that's actually the only book I used. What did it for me was trial-and-error and practice, but the most important part was getting the basics down so I could start reading through other people's good code.
Re:Modern C, Second Edition by codesushi42 on Thursday September 19, 2019 @02:00AM (#21013693)
K&R is a classic. A true exemplar of technical writing.
Re:Modern C, Second Edition by Gibbon1 on Wednesday September 18, 2019 @03:56PM (#21009383)
If someone tells you to use K&R take that as license to ignore their advice from that point on.
Re:Modern C, Second Edition by valacmur98 on Wednesday September 18, 2019 @05:01PM (#21010153)
I am using it to study C. Can you tell me the reason why you wouldn't recommend it?
Re:Modern C, Second Edition by ThrowawayR2 on Wednesday September 18, 2019 @05:40PM (#21010528)
Despite being amazingly well written, the most recent edition of K&R was published in 1988. The current version of C is C18, released last year, so K&R is missing about 30 years of evolution. It's not a bad book, by any means, but it doesn't include important aspects about how C is used today.
Re:Modern C, Second Edition by ufo on Wednesday September 18, 2019 @06:25PM (#21011023)
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).

Re:Modern C, Second Edition by einpoklum on Thursday September 19, 2019 @04:24AM (#21014375)
You meant:

while ((dst++) = (src++))

I believe.

Re:Modern C, Second Edition by Gibbon1 on Thursday September 19, 2019 @05:17AM (#21014580)
while ((dst++) = (src++));
Re:Modern C, Second Edition by billforsternz on Thursday September 19, 2019 @07:21AM (#21015183)
Both 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.

Re:Modern C, Second Edition by Gibbon1 on Wednesday September 18, 2019 @06:17PM (#21010925)
Because it's 30 years out of date. It's missing three revisions of the language. Teaches a lot of practices that lead to obtuse brittle code riddled with security holes.

Avoid.

Re:Modern C, Second Edition by hnbroseph on Wednesday September 18, 2019 @11:02PM (#21012849)
can you be more specific about these practices?
Re:Modern C, Second Edition by Gibbon1 on Thursday September 19, 2019 @12:19AM (#21013257)
What ufo said

> implements strcpy as `while(dst++ = dst++);

The book is full of stuff like that.

Re:Modern C, Second Edition by cma on Thursday September 19, 2019 @12:53AM (#21013398)
Doesn't strcpy always have that issue? The terseness is one issue, but the security problem is that it implements strcpy at all without warning.
Re:Modern C, Second Edition by iamnotacrook on Thursday September 19, 2019 @06:25AM (#21014928)
You tend to get warnings to use the _s versions of some functions (strcpy_s in this case) these days.
Re:Modern C, Second Edition by cesarb on Thursday September 19, 2019 @08:16AM (#21015439)
I just tried (with gcc 9.2.1), and got no warning. As far as I know, these _s versions aren't that good, and often aren't available at all; see http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm which says among other things

"[...] none of the popular Open Source distribution such as BSD or Linux has chosen to make either available to their users. At least one (GNU C Library) has repeatedly rejected proposals for inclusion [...]"

"[...] As a result of the numerous deviations from the specification the Microsoft implementation cannot be considered conforming or portable."

Re:Modern C, Second Edition by iamnotacrook on Thursday September 19, 2019 @09:41AM (#21016038)
"often aren't available at all"

It's in C11. Perhaps Red Hat use non-compliant compilers, or very, very old ones?

Re:Modern C, Second Edition by cesarb on Thursday September 19, 2019 @10:54AM (#21016745)
It's an optional part of C11, which means that even a fully compliant compiler does not have to implement them.
Re:Modern C, Second Edition by lone_haxx0r on Thursday September 19, 2019 @07:31PM (#21021779)
strcpy_s has no manual entry on Ubuntu, while "man strcpy" and "man strncpy" work as expected.

Why would that be?

Re:Modern C, Second Edition by saagarjha on Wednesday September 18, 2019 @05:22PM (#21010362)
I really enjoyed it, but it’s best supplemented with exposure to modern C syntax and an introduction to undefined behavior.