Live data from Hacker News

Massacring C Pointers

wozniak.ca

221–230 of 300 posts

Re: Massacring C Pointers

#221
post #98
post #90

Earlier quoted context omitted.

No, all of that example was malpractice in the 80s when it was written. Note the context: it's highlighted as malpractice in a talk by Brian Kernighan!

I'll bite: argument from authority can be reversed - if Brian didn't mess up the language design, these sorts of "code drivels" wouldn't have appeared! I think you've heard that argument from many language designers already... Then we can argue that back in those times it was something progressive etc. And we are straight back with the argument I was making. When you read StackOverflow, books on Deep Learning or comp…

> if Brian didn't mess up the language design, these sorts of "code drivels" wouldn't have appeared!

OK, ignoring the s/Brian/Dennis/ snafu... WTF is a "code drivel"? What are you trying to say here?

Second, your point is irrelevant: It's pointless to write a book about driving cars and fill it with a long rant about how riding motorcycles is so much better. It's a non sequitur, and false advertising. Much like how this book is presented as a good resource for learning C and is, in fact, a horrible example of precisely how little the author understood C.

> Then we can argue that back in those times it was something progressive etc.

Aside from your infelicitous attempt at English, this is wrong: This book was never good, and claiming it was insults the past.

Re: Massacring C Pointers

#222
post #148

This was a fun read, but left me with the question: What book on C pointers would be the polar opposite of this one? I'd like to read that book.

While I haven't read either of them, Pointers on C and Understanding and Using C Pointers both have good reviews.

Re: Massacring C Pointers

#223
post #70

This doesn't surprise me really. When I was at university the programming textbooks we had were vile nasty and plainly incorrect. And those of us who dared challenge it by writing correct, robust code were penalised as the staff teaching it didn't understand the domain of what they were teaching properly and didn't have any real experience and assumed we were doing it wrong. We learned quickly to approach education w…

One of the reasons I don't consider a degree anything of value when evaluating candidates. It might be a baseline or it might be a red herring. Best to just assume a degree and no degree are equal and asses based on practical examples.

I would think a degree would be valuable, if for nothing else, then because it indicates a willingness to put in 4 years of work to achieve a challenging goal. Conscientiousness is the word, I believe. A university degree shows you have some minimum level of conscientiousness.

Re: Massacring C Pointers

#224
post #74

Earlier quoted context omitted.

To be fair, he said that about a lot of mainstream languages back then. That quote is from EWD498 at http://www.cs.utexas.edu/users/EWD/transcriptions/EWD04xx/EW... . The larger context is (the rest of the comment quotes him): FORTRAN —"the infantile disorder"—, by now nearly 20 years old, is hopelessly inadequate for whatever computer application you have in mind today: it is now too clumsy, too risky, and too expen…

Having a discussion with someone who quotes Dijkstra can be frustrating. He wrote Go To Statement Considered Harmful and On the Cruelty of Really Teaching Computer Science and left behind a bunch of pithy quotes to mine besides. You end up having to explain why blanket bans on goto don't make sense, why it really is quite difficult to mathematically prove that a program works, or why it makes sense to teach students…

Dijkstra is the Nietzsche of computer science: Eminent, quotable, often irritated, and prone to be taken exactly the wrong way by people who only half-understand his ideas.

Re: Massacring C Pointers

#225
post #110
post #63

Earlier quoted context omitted.

You're right, although any mention of strncpy should come with a big disclaimer that it's effectively broken because you can end up with a non-NULL terminated string in some cases. strlcpy should be the way to go but unfortunately it's not part of the C standard and not available everywhere (sometimes for rather bullshit reason IMO, but that's a different story).

Documented behaviour is a little different to "effectively broken". The difference between strncpy and strlcpy is that strlcpy will NUL terminate the last byte for you always. There is nothing stopping you from doing the same thing yourself when you use strncpy. If you care enough, write your own strlcpy - it's only one extra line.

A documented behavior which causes many security and crash issues is, almost be definition, effectively broken.

Can you come up with an example of an API which you would consider to be effectively broken and yet is not actually broken? Presumably, it would be an API that's easier to misuse than strncpy.

Re: Massacring C Pointers

#226
post #94

The fixed-location variable allocation strategy the author mentions is called overlaying or compile-time stack[0]. It's still very much alive today, thanks to architectures like 8051 that are not really stack-friendly (even though they do have a stack). > The Keil C51 C Compiler works with the LX51 Linker to store function arguments and local variables in fixed memory locations using well-defined names [0] http://www…

Is there anything I can read to learn more about overlaying in C? I was reading, to my limited abilities' limits, 2.11 BSD source and there was a lot of references to overlaying.

Re: Massacring C Pointers

#227
I've definitely bought a few programming books that, on closer inspection, just appeared to be money-grabs from the author.

But, my biggest memory is the book I didn't buy. I once worked with a programmer who wasn't very good, and then I heard he wrote a book. I typed his name into Amazon, and there was his book. It was all about the half-baked concepts he was trying to put into our failing project. (Ultimately canceled because we couldn't ship a very simple product. We couldn't ship it because everyone just wanted to add code generators and additional layers around a database... Instead of learning how to use a database.)

I couldn't get out of that job fast enough.

Re: Massacring C Pointers

#228

Earlier quoted context omitted.

What’s safer about it? Doesn’t `strlen' just scan until the null character, then go nullCharPtr - str ? Is there something unsafe with that?

What if there is no null?

If there isn't a NUL, then you're asking for a property relevantly distict from length of a datum relevantly distinct from a C-string. Use `strchr(s,0x00)` or `memchr(s,0x00,zs)`.

Re: Massacring C Pointers

#229
post #221
post #98

Earlier quoted context omitted.

I'll bite: argument from authority can be reversed - if Brian didn't mess up the language design, these sorts of "code drivels" wouldn't have appeared! I think you've heard that argument from many language designers already... Then we can argue that back in those times it was something progressive etc. And we are straight back with the argument I was making. When you read StackOverflow, books on Deep Learning or comp…

> if Brian didn't mess up the language design, these sorts of "code drivels" wouldn't have appeared! OK, ignoring the s/Brian/Dennis/ snafu... WTF is a "code drivel"? What are you trying to say here? Second, your point is irrelevant: It's pointless to write a book about driving cars and fill it with a long rant about how riding motorcycles is so much better. It's a non sequitur , and false advertising. Much like how…

I love intellectual debates, but this really isn't one. I just have the feeling this is an "intellectual" mob in progress. BTW, it's wonderful to attack people for their English skills; I speak 8 languages but not all of them at C2 level, despite being grad at one of top US colleges. Would you take my sincere apologies for offending you by not being on your level?

Re: Massacring C Pointers

#230

When I started my CS degree the school was transitioning from teaching C++ to teaching Java, and the state of instruction in C++ was almost as bad as these examples. I had a professor who wanted us to use "new Foo()" everywhere in our code (even local / static variables) because it, "gets the students ready for Java." No matching delete, of course, or mention of RAII. We were supposed to "pretend" we had a garbage co…

> I think he took it with more grace than I deserved.

That kind of righteous fury is very common in high school and undergrads. Teachers have to perform in front of a tough crowd.

Post reply on HN