Live data from Hacker News

Deconstructing K&R C Is Dead (2015)

c.learncodethehardway.org

101–110 of 190 posts

Re: Deconstructing K&R C Is Dead (2015)

#101

Earlier quoted context omitted.

There are so many to choose from. Here is one I just thought up: void free_circularly_linked_list(struct node *head) { struct node *tmp = head; do { struct node *next = tmp->next; free(tmp); tmp = next; } while (tmp != head); } Can you spot the undefined behavior?

The `tmp != head` comparion is UB because `head` is a dangling pointer after the first loop iteration, right?

Why is it UB?

Let's say head value is "10" and the memory at "10" is {..., next: "10"}

After the first iteration we will have:

Head: "10" Next: "10" Temp: "10"

With "10" pointing to freed memory. But why do we care? We are not dereferencing it, are we?

(I think I am missing something very obvious)

Re: Deconstructing K&R C Is Dead (2015)

#102
post #54
post #6

Low level languages are tough. Gaining a mastery of C does require knowing quite a few strange rules and quirks and it's certainly a bit harder than learning Python. The C FAQ does a good job of illustrating some of the more confusing parts. Sure, I wish I could write Go instead, but that isn't going to happen on the many embedded systems I work on. This is a rather strange and insulting article. I'm not sure why Zed…

> Low level languages are tough I disagree. Low level languages, especially C, are the easiest to master. K&R book is the only book you need to read to know everything about C. All you need after you understand the fundamentals is a bit of discipline. C++ on the other hand is extremely difficult to master. Just have a look at the rules for Rvalue references and you will see what I mean. It may be easier for a complet…

These days I'd say the ISO standard is the only "book" you need to know everything about C.

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf is the most recent draft before the official, purchase-only C11 was published according to http://www.open-std.org/jtc1/sc22/wg14/www/standards. I don't know if it's identical, but it should be close, and it's free.

Re: Deconstructing K&R C Is Dead (2015)

#103
post #2

I am one of the many stalwarts whose bookshelf contains a prominent copy of K&R C. But over the last 10 years or so I find myself referring to it less and less often. It's a huge problem that it stopped at the second edition. The 2nd ed was great in 1999. It is not great in 2016, it is only good. > "You're right, but you're wrong that their code is bad." I cannot fathom how a group of people who are supposedly so int…

> Gotta love mixing up C with natural language operator precedence ambiguity. :)

Well, then, in that case you shouldn't you reall refer to it as K&&R

Re: Deconstructing K&R C Is Dead (2015)

#104

Do remember that this guy wrote: "I’ve more or less kept my mouth shut about some of the dumb and plain evil stuff that goes on in the Rails community. As things would happen though I’d take notes, collect logs, and started writing this little essay. As soon as I was stable and didn’t need Ruby on Rails to survive I told myself I’d revamp my blog and expose these fucks." and: "After Mongrel I couldn’t get a gang of m…

I don't think bringing out a list of generically outrageous things someone said in the past rises to the level of discourse we're trying for here.

We detached this subthread from https://news.ycombinator.com/item?id=11727718 and marked it off-topic.

Re: Deconstructing K&R C Is Dead (2015)

#106
post #101

Earlier quoted context omitted.

The `tmp != head` comparion is UB because `head` is a dangling pointer after the first loop iteration, right?

Why is it UB? Let's say head value is "10" and the memory at "10" is {..., next: "10"} After the first iteration we will have: Head: "10" Next: "10" Temp: "10" With "10" pointing to freed memory. But why do we care? We are not dereferencing it, are we? (I think I am missing something very obvious)

Because the standard says even comparing a dangling pointer is UB, which was haberman's point about the standard being non-intuitive.

Re: Deconstructing K&R C Is Dead (2015)

#107
post #101

Earlier quoted context omitted.

The `tmp != head` comparion is UB because `head` is a dangling pointer after the first loop iteration, right?

Why is it UB? Let's say head value is "10" and the memory at "10" is {..., next: "10"} After the first iteration we will have: Head: "10" Next: "10" Temp: "10" With "10" pointing to freed memory. But why do we care? We are not dereferencing it, are we? (I think I am missing something very obvious)

I think you’re missing the fact that "There are a lot of rules you need to be aware of that are not naturally-occurring results of the fundamentals."

Re: Deconstructing K&R C Is Dead (2015)

#108
post #31

FYI, this rant is from January 2015. Surprised to see it showing on HN today. If anyone is interested in what he removed, you can find it here: https://web.archive.org/web/20150101224641/http://c.learncod...

It wasn't obvious when this dates from, but we'll take your word for it and add 2015 to the title.

Re: Deconstructing K&R C Is Dead (2015)

#109
post #24

I can't really speak for Zed's expertise and/or value to the programming community. From what I gather, a few of his projects are widely used (Mongrel comes to mind), and he seems to know his stuff pretty well. I also identify strongly with his Programming Motherfucker[0] rant. But man, the guy is insecure to the point of requiring therapy or something. He seems obsessed with his image and status, and the slightest c…

Wow, [1] is pretty far out there, what with taking on the worldwide conspiracy to deny him recognition as History's Greatest Genius. Has he at least mellowed out since 2007?

  >Has he at least mellowed out since 2007?
Yes

Re: Deconstructing K&R C Is Dead (2015)

#110

Earlier quoted context omitted.

Wow, [1] is pretty far out there, what with taking on the worldwide conspiracy to deny him recognition as History's Greatest Genius. Has he at least mellowed out since 2007?

>Has he at least mellowed out since 2007? Yes

Not by much though.

https://zedshaw.com/2015/06/01/dear-paul/

Post reply on HN