Fog Creek Software
Discussion Board

Pointers on pointers?

Hi Joel,

I've been working on SQL and VB for the past few years, which I've pretty much learned myself after graduating with a science degree. I feel now, though, that my lack of formal CS training is going to come back and get me sooner or later.

You're 'Back to basics' article struck a chord, and I feel that I *could* be a reasonable programmer with the right material to digest. Do you know of any online information I could use to assess my aptitude for programming? Stuff like 'If you can understand these articles on pointers/ algorithm development then you're heading in the right direction!' Am I being overly simplistic?

I just feel like learning to code database applications with a language like VB has removed me from a lot of the stuff that I feel would interest me most. Is K&R's 'The C Programming Language' the place to start? If not, where?

Thanks in advance,


Thursday, February 26, 2004

K&R! Exactly what I was going to suggest!

Joel Spolsky
Fog Creek Software
Thursday, February 26, 2004

If you are using VB, you probably have access to VC++. You can try out what you learn in K&R by creating console applications in VC++. Don't get too distracted with Win32 or MFC AppWizard at this point.

Thursday, February 26, 2004

"Structure and Interpretation of Computer Programs" and "The Art of Computer Programming".  From the first you'll get a good start on the high-level stuff, from the second a good start on low-level algorithms and "real machine programming".  You might also give the Feynman lectures a read if you're serious about peeling away as much of the onion as you can (it's the next logical step from Joel's 'principle of leaky abstractions').

Thursday, February 26, 2004

I've found "Reliable Data Structures in C" by Thomas Plum to be very clarifying.  The emphasis on the title should be on RELIABLE, not Data Structures, as it's mostly how to code reliably in 'C'.

It is more focused on the issues Joel has raised than most 'C' language tutorials.  Questions like, what makes a good library?  What makes a good primitive function?

Note this book has LOTS of links to an earlier Plum book, which you can safely ignore.

So the K&R book, and this one, would be a minimal good start.

Thursday, February 26, 2004

Joe: "Say, do you know of any online information I could use to assess my aptitude for programming?"
Kay: "Why Yes, 'Structure and Interpretation of Computer Programs' and 'The Art of Computer Programming' and the Feynman Lectures.


Dennis Atkins
Thursday, February 26, 2004

Practical C Programming by Steve Oualline, from O'Reilly & Associates.

Honestly, K&R (2nd ed.) is almost 20 years old. The code examples are littered with buffer overflows, one-letter variable names, and the writing is as dry as a bone. It's meant for a someone with a substantial amount of experience with a low-level procedural language like FORTRAN or COBOL, and isn't welcoming to the beginner.

Practical C Programming actually makes C *fun*--I finished it in a matter of days. Honestly, even if you have no programming experience, you can understand this book. It will show you how to use pointers, make linked lists, and contains exlpanations of the stuff most books (like K&R) expect you to already know, like how to use bit masks and bit flags. You'll probably have to read K&R too, but Practical C Programming is superb.

Jay FN
Friday, February 27, 2004

is a chapter on pointers from the book above

Friday, February 27, 2004

Here's a pretty decent online tutorial about pointers:

For me, the moment that the clouds parted and rays of sunshine broke through was when this tutorial pointed out that

"The parameter passed to puts() is a pointer, that is the value of a pointer (since all parameters in C are passed by value), and the value of a pointer is the address to which it points, or, simply, an address."

Everyone else seems to say that in C you can either pass by value or by reference.  I find it easier to think that you _always_ pass by value, but sometimes the value you're passing happens to be an address rather than an int or a float or whatever.

Friday, February 27, 2004

Kyralessa, your version entirely misses the point that passing by value creates a new copy of the data while by reference just give you another pointer to same data.

Monday, March 1, 2004

When you pass a pointer's address by value, you really do get a whole separate copy of the pointer's address.  Since it was the address, not the data at that address that was copied, no copy is made of the thing to which the pointer refers.

That is important to realize in C, because you have to know that if you set the pointer to NULL in the function, the caller won't see NULL back from that parameter when the function returns.  That is why if you want to send a pointer's value by reference, you have to really send the value of a reference to the pointer's value.

See how easy that is?

Keith Wright
Friday, March 5, 2004

Learn assembler first. Once you understand the indirect load/store/jump opcodes of a typical CPU, pointers will be no problem.

It's this aspect of C that leads some to call it "portable assembler".

Saturday, March 20, 2004

*  Recent Topics

*  Fog Creek Home