
Laurence Tratt: How can C Programs be so Reliable? - swah
http://tratt.net/laurie/tech_articles/articles/how_can_c_programs_be_so_reliable
======
derleth
First: Pointers do have a simple real-world analogy. They're post office box
numbers.

A given post office box is a container with a fixed size and a fixed number.
You can refer to a post office box using that number. You can also do things
like say "Get me everything from the four post office boxes beginning with
post office box 20." or "Go to post office box 3, go down two boxes, and get
me what's in the post office box there."

Finally, you can write a post office box number down and stick it into a
different post office box. Then, to get anything useful, you have to say
things like "Go to post office box 15, open it and read the piece of paper
inside, go to the post office box with the same number as the one written on
the piece of paper you just read, and get me what's in that box." You can
actually 'chain' requests like these for a long way, with one post office box
having a piece of paper with the number of the next post office box written on
it. This gets screwy after the third or fourth box.

Anyway, the post office is the simplified notion of RAM your OS gives
application programs, a given post office box is a RAM location (byte or
word), and a post office box number is a pointer.

The rest of the article is basically "You _can_ program carefully enough to
make C programs robust." and that is, in fact, true. I use robust C programs
every day, one of them being the Linux kernel. However, the actual debate is
over whether it's worth taking the time to be that careful when you could use
a different language which makes a lot of mistakes impossible.

~~~
mstroeck
This. I've always wondered what's so difficult about pointers for some people,
mainly because I used a similar mental model from the very beginning.

