Live data from Hacker News

Beej’s Guide to C Programming [pdf]

beej.us

71–80 of 178 posts

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

#71
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 1st one I guess.

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

#72

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…

You can always check reviews published by ACCU.org:

K. N. King "C Programming":

https://accu.org/bookreviews/1999/graham_1260/

Ben Klemens "21st Century C":

https://accu.org/bookreviews/2016/demin_1882/

Robert C. Seacord "Effective C":

https://accu.org/bookreviews/2020/glassborow_1952/

https://accu.org/bookreviews/2021/bruntlett_1959/

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

#73
post #30

Earlier quoted context omitted.

In C, pointers require you to think deeply about the ownership and lifetime of any "allocated object" at runtime. How long does it live, who is responsible for the deallocation, how many pointers does your program hold to that object (dangling issues). Ultimately, it can lead to a cleaner design if these issues are taken seriously up-front.

I don't disagree with that, but most cases fall within a pretty clear pattern: - typedef struct { ... } foo - foo *foo_create() - void foo_destroy(foo *) - a bunch of functions that take foo* as their first arg which is kind of the same as a class and only more error-prone. I say this as someone who actually _likes_ C, but the manual memory management model is very often unnecessary, confusing, repetitive. There was…

Yeah, except when it doesn't follow the pattern: for example, there is no foo_destroy(), you're supposed to "just" call free() when you're done with it. Used to be very common (not sure how it is now), and very frustrating when you link against non-standard allocators.

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

#75
post #74

This is a wonderful book if you want to understand how the OSI model of internet works, clearly illustrated network apis. Man this book was amazing.

I think you’re confusing it with another book. This is a guide to C programming. You’re probably thinking of Beej's Guide to Network Programming :)

https://beej.us/guide/bgnet/

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

#76
post #6

IMO, pointers are less difficult to comprehend than other abstractions, like lambdas are. If you know how to walk down a street and stop at the right street number, then you have used pointers. And if you've ever observed that one tall building may "cover" a range of street numbers, such as 200-220, then you should understand how to move from one 4-byte "value" to the next in an array in memory. Anyway, many more ana…

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

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

#77
post #28
post #16

Earlier quoted context omitted.

What's difficult to understand about pointers isn't the concept of a pointer itself, or even * and &, it's the fact that working with pointers requires you to simultaneously understand different abstraction levels. While it's not unique to pointers, and it's in fact the case for most nontrivial programming tasks, what's unique about C is that pointers are so pervasive you can't really do anything if you don't underst…

These are good points. I can sometimes feel that Python is more pointer-y (?) than people expect, with stuff like: a = {"one": 1, "two": 2 } b = a b["two"] = 99 print(a["two"]) The above prints 99, since "b = a" does not copy the value (the dictionary) but just the reference to the value ("the pointer", kind of). This is surprising to some people.

This is one part (of many) of perl that I like, that it exposes the pointer-y parts to the programmer (to abuse :))

    # hash
    my %a = ( 'one' => 1, 'two' => 2 );
    my %b = %a;

    $b{ 'two' } = 99;

    # prints 2
    print $a{ 'two' }, "\n";

    # reference to hash
    my $a = { 'one' => 1, 'two' => 2 };
    my $b = $a;

    $b->{ 'two' } = 99;

    # prints 99
    print $a->{ 'two' }, "\n";

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

#78

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…

You can always check reviews published by ACCU.org: K. N. King "C Programming": https://accu.org/bookreviews/1999/graham_1260/ Ben Klemens "21st Century C": https://accu.org/bookreviews/2016/demin_1882/ Robert C. Seacord "Effective C": https://accu.org/bookreviews/2020/glassborow_1952/ https://accu.org/bookreviews/2021/bruntlett_1959/

Wow I never heard of Robert Seacord's 'effective C'. Thank you.

Edit: Here's a short rationale for the book by the author.

https://ieeexplore.ieee.org/document/9237323

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

#79
post #57

Earlier quoted context omitted.

But int-pointer is the type of it. It makes no sense that it “sticks” to the variable name.

There's a type and an identifier. In `int *pa[10]`, the identifier is `pa` and the type is `int *[10]`. A declaration simply specifies a name (the identifier), some operations around it (pointer dereferencing, array subscription, function calling, grouping parentheses) and the terminal type that you get after applying all those operators in the precise order as specified by operator precedence rules. When using that…

Thank you for the concise write up, but I think lowly of the [] syntax as well.

And unary operators on an identifier are a different thing, though I similarly don’t think adding one at the left, another at the right is a good thing. But I have trouble with the declaration site as well.

It’s getting out of reach of my knowledge, but I believe C’s grammar being hacky is in part due to that as well.

I didn’t find exactly what I was looking for but here is some more on it: https://pdos.csail.mit.edu/archive/l/c/roskind.html

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

#80
post #57

Earlier quoted context omitted.

But int-pointer is the type of it. It makes no sense that it “sticks” to the variable name.

You missed the whole point. Yes, it makes no sense until you grok the logic of it and then it starts making sense (while still being unintuitive). Re-read the comments you are responding to.

Yeah I get that it has logic (though by being pedantic, anything we can write a parser for has logic, but I’m sure we could create some stupid languages), but as you yourself note, not very intuitive. And as far as I know, it doesn’t ease the work of parser-writers.
Post reply on HN