Live data from Hacker News

Beej’s Guide to C Programming [pdf]

beej.us

11–20 of 178 posts

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

#11
post #7

I've enjoyed this guide a number of times but each time I hit a brick wall trying to understand pointers. I'm still keen to learn but it just doesnt 'click' for me... Edit: poor grammar

Just learn C by reading and working through the K&R book. (It's one of the best CS books ever written.)

https://www.amazon.com/Programming-Language-2nd-Brian-Kernig...

Also, there's nothing magical about pointers - scripting languages use "handles", which is the same thing except they're read-only to the end-user programmer.

The real challenge with C is multi-threaded programming, so don't do that if you don't need it.

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

#12
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…

What pointers basically are is not particularly hard to grasp. What is harder to grasp it what can be done with them and how you can shoot yourself in the foot with them in non-obvious ways.

I think I only understood much of it once I learned Rust, because you realize: Ah, that thing I once did in C is something that maybe ahouldn't be possible at all without extra steps. Even if I were to nwver use Rust again, this definitly helped to understand how to use pointers more safely.

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

#13
it actually has working examples for all of the C library calls even math routines. Not sure if it's complete but it seems so. This seriously helps bridging the gap between man (2) pages and putting things into working code and only beef I have is that I didn't have it 25 years ago. Very cool.

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

#14
post #7

I've enjoyed this guide a number of times but each time I hit a brick wall trying to understand pointers. I'm still keen to learn but it just doesnt 'click' for me... Edit: poor grammar

Just another integral data type which supports not only arithmetic (adding or removing an integral value), but also "dereferencing" which means getting a value of the pointed-to type at the pointed-to address.

The quantities added or removed in arithmetic operations are the same as the size of the type that is being pointed to.

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

#16
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…

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 understand how to work with them.

IME languages like Python aren't any easier than C to work with (ignoring UB issues of course), but it's certainly the case that you can probably kinda sorta get your job done with Python even without understanding the first thing of what you're doing, and that's not happening if you write in C.

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

#17
> It’s especially insidious because once you grok pointers, they’re suddenly easy. But up until that moment, they’re slippery eels.

I'm sort of a C beginner myself. I understand pointers, and I do remember they clicked in my mind suddenly. The moment before, I didn't understand at all. I also love the quirkiness of this guide. Definitely going to give this a read.

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

#18
post #7

I've enjoyed this guide a number of times but each time I hit a brick wall trying to understand pointers. I'm still keen to learn but it just doesnt 'click' for me... Edit: poor grammar

A pointer is a level of indirection.

A regular variable is a place in RAM that contains a certain value.

A pointer is a variable whose value is the address of another variable.

X = 5

Y = location in memory of X

Now you can use Y to manipulate X

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

#19
post #7

I've enjoyed this guide a number of times but each time I hit a brick wall trying to understand pointers. I'm still keen to learn but it just doesnt 'click' for me... Edit: poor grammar

Just learn C by reading and working through the K&R book. (It's one of the best CS books ever written.) https://www.amazon.com/Programming-Language-2nd-Brian-Kernig... Also, there's nothing magical about pointers - scripting languages use "handles", which is the same thing except they're read-only to the end-user programmer. The real challenge with C is multi-threaded programming, so don't do that if you don't need i…

> Just learn C by reading and working through the K&R book. (It's one of the best CS books ever written.)

This is really an amazing feat: books on programming languages age really fast. This one - not so much. And you can really appreciate the careful thought that was put in each sentence. Peerless.

> The real challenge with C is multi-threaded programming, so don't do that if you don't need it.

Well, these days it's harder and harder to avoid it if you want to write efficient apps - we got more cores and the clocks remain more or less the same.

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

#20

> It’s especially insidious because once you grok pointers, they’re suddenly easy. But up until that moment, they’re slippery eels. I'm sort of a C beginner myself. I understand pointers, and I do remember they clicked in my mind suddenly. The moment before, I didn't understand at all. I also love the quirkiness of this guide. Definitely going to give this a read.

Do you mean the general concept or like: a is a pointer to an array of functions which return pointers to functions which return ints and take double arrays as parameters.

This somehow never really clicked (or actually it clicked and declicked somehow)

Post reply on HN