Live data from Hacker News

Beej’s Guide to C Programming [pdf]

beej.us

171–178 of 178 posts

Re: Beej’s Guide to C Programming [pdf]

#171

I haven't read these 2 books, but would like the opinion of someone who did. [1] C Interfaces and Implementations: Techniques for Creating Reusable Software by David Hanson - HN's tptacek seemed to rave about this book, that's how I heard of it. Wonder what he thinks of it in 2021. [2] C Programming: A Modern Approach by K. N. King - this one seems to be loved by many. Seems to be more 'beginner-friendly' than the 1s…

It remains my favorite C book, though: I don't think you should write much C anymore.

Re: Beej’s Guide to C Programming [pdf]

#172

I haven't read these 2 books, but would like the opinion of someone who did. [1] C Interfaces and Implementations: Techniques for Creating Reusable Software by David Hanson - HN's tptacek seemed to rave about this book, that's how I heard of it. Wonder what he thinks of it in 2021. [2] C Programming: A Modern Approach by K. N. King - this one seems to be loved by many. Seems to be more 'beginner-friendly' than the 1s…

It remains my favorite C book, though: I don't think you should write much C anymore.

My favorite is Expert C Programming: Deep C Secrets by Peter van der Linden. I started it as soon as I encountered C at university and could only get through about a chapter at a time. By third year when the assignments in C got hard I was in a great position, partly for this book. Even crazier is I enjoyed it.

Re: Beej’s Guide to C Programming [pdf]

#173
post #163

Earlier quoted context omitted.

While experienced C programmers that care about security wouldn't even touch strcpy() . All those code samples will crash and burn if s and t point to the wrong locations, t happens to point to a string without a null terminator, or s points to a buffer not big enough to handle the string pointed by t.

> All those code samples will crash and burn if s and t point to the wrong locations This is true for all uses of pointers in C. The only validation you can do is whether a pointer is null. Apart from that you can never know that a pointer points to a non-wrong location. And still experienced C programmers seem to be OK with using pointers.

Actually no, many OSes do have APIs to validate pointer integrity.

But even then, most experienced C programmers don't care about using them anyway, that is why Apple, Oracle, Microsoft, ARM, Google, Cambridge university are all leading efforts for hardware memory tagging.

So it won't matter how much they care, as the OS will kill their beloved application when pointers get misused.

A scenario already made reality in platforms like Solaris SPARC.

Re: Beej’s Guide to C Programming [pdf]

#174
post #87
post #76

Earlier quoted context omitted.

For anyone who wants to learn about pointers I can recommend studying a language simpler than C like for instance Oberon where pointers are more restricted. Having a look at Oberon can also broaden your view even if you know pointers in C. https://www.miasap.se/obnc/oberon-report.html http://people.inf.ethz.ch/wirth/Oberon/PIO.pdf

Actually, this could confuse things even more, because the C pointer and Oberon's POINTER TO have very little in common.

When pointers are used to build dynamic data structures the differences are merely syntactical.

Re: Beej’s Guide to C Programming [pdf]

#175
post #155

Earlier quoted context omitted.

Just wanted to say THANK YOU as I read your guide to network programming way back in 2000, over 20 years ago! I was just starting out in C network programming on VxWorks :) Glad to see you're still updating your guides.

Thanks! Makes my day to hear people find the work useful. :)

I read the beginning of this C guide and also found it very helpful and made things very easy to understand (coming from C++). Thanks!

Re: Beej’s Guide to C Programming [pdf]

#176
post #173

Earlier quoted context omitted.

> All those code samples will crash and burn if s and t point to the wrong locations This is true for all uses of pointers in C. The only validation you can do is whether a pointer is null. Apart from that you can never know that a pointer points to a non-wrong location. And still experienced C programmers seem to be OK with using pointers.

Actually no, many OSes do have APIs to validate pointer integrity. But even then, most experienced C programmers don't care about using them anyway, that is why Apple, Oracle, Microsoft, ARM, Google, Cambridge university are all leading efforts for hardware memory tagging. So it won't matter how much they care, as the OS will kill their beloved application when pointers get misused. A scenario already made reality in…

> many OSes

Are outside the scope of the C language. But if you allow these special APIs, you can use them to implement a safe strcpy. Either way your point from above is still invalid.

Re: Beej’s Guide to C Programming [pdf]

#177
post #117

Again, the string chapter is telling us about zero-terminated char arrays/pointers and doesn't even mention Unicode/UTF-8 or safety :-(

I do have a chapter on Unicode and wide characters, but it's separate from the "classic" strings chapter. That said, I could certainly refer forward to it. And C11 only has minimal portable UTF-8 support, but I do talk about it. I think C21 will improve on that a bit. A note on safety would be well worth it. I'll do that. Good suggestion.

Cool. Thank you. Lack of coverage of this subject in educational materials has been pain ever since I was studied C at school. All the books said that: strings are zero-terminated char arrays. But this kind of strings is almost useless in today globalized world. Sorry I didn't notice you cover this topic in a separate chapter. This makes your guide really great. Let me suggest you mention that chapter in the strings chapter unless you have a reason to omit such a reference. Thank you for a great job!

Re: Beej’s Guide to C Programming [pdf]

#178

Earlier quoted context omitted.

It remains my favorite C book, though: I don't think you should write much C anymore.

My favorite is Expert C Programming: Deep C Secrets by Peter van der Linden. I started it as soon as I encountered C at university and could only get through about a chapter at a time. By third year when the assignments in C got hard I was in a great position, partly for this book. Even crazier is I enjoyed it.

My only complaint about that book is the title - by the time I'd got to it I was nodding along to things I'd figured out long before or nitpicking things that were "merely" right enough to be useful. Maybe I was already solidly expert, but I feel like for most things programming the knowledge available is so broad that there will be some significant gaps between experts; in any case, I wish I had picked it up ten years prior.
Post reply on HN