Pointer Analogies

P

pemo

After sooo many years, I've just re-read Tracy Kidder's The Soul of a New
Machine - the guy really knows how to explain things to the lay reader [thus
the Pulitzer]! E.g., an abridged extract on addressing/memory:

". the main issue was the computer's storage system. The situation resembles
that of a region's telephone system; telephones are of no use unless they
are distinct one from the other, and an item in a computer's storage system
is of no use unless it can easily be found. The general solution resembles
the phone company's; each compartment in the computer's storage has its own
'phone number,' its own unique symbol, known as an address"

When I read that I started to think if there was some 'real-world' analogy I
could use to initially discuss *pointers* in C.

On the telephone theme, I started thinking about mobile phones and wondered
whether I could use a person's number as a kind of pointer-to-person thing.
I also thought about email addresses. However, my phone number doesn't get
to 'me', it get's to my mobile - same for my email address [of which I have
many - which can 'work' here of course: many pointers to the same object].

Having rejected these though, I thought about things like ISBN, and book
[Dewey Decimal] references, e.g., 127.56.3 in our library points to K&R
[which is always there]. Dewey references - being very similar to IP
addresses, I thought about IP addresses directly, but stuck with DNS
resolved addresses e.g., using something like:

BBC * www.bbc.co.uk //A pointer to the BBC - um?

Ok, it doesn't give me *the* BBC, but a page on the BBC's website - but you
get the idea?

The website/URL thing does have one added bonus, in that pointer to
pointers - if this analogy holds - can also be factored in i.e., say, you go
to a website and find that it's moved, and that the old pages re-direct you
to the new website, e.g., by dereferencing the initial URL the
data/'information' you get is another URL which when dereference gets you to
the website you're looking for.

Anyway, I'd be interested in hearing what others think about these
analogies, and whether they think they're 'close enough' to form an initial
hook into the function of pointers. Of course, better analogies form the
real-world would be very welcome, esp. if they allow different references to
'point' to the same object [like email addresses], and, at the same time,
can be used to get the pointer-to-pointer concept across.
 
A

Andrew Poelstra

After sooo many years, I've just re-read Tracy Kidder's The Soul of a New
Machine - the guy really knows how to explain things to the lay reader [thus
the Pulitzer]! E.g., an abridged extract on addressing/memory:

". the main issue was the computer's storage system. The situation resembles
that of a region's telephone system; telephones are of no use unless they
are distinct one from the other, and an item in a computer's storage system
is of no use unless it can easily be found. The general solution resembles
the phone company's; each compartment in the computer's storage has its own
'phone number,' its own unique symbol, known as an address"

When I read that I started to think if there was some 'real-world' analogy I
could use to initially discuss *pointers* in C.

On the telephone theme, I started thinking about mobile phones and wondered
whether I could use a person's number as a kind of pointer-to-person thing.
I also thought about email addresses. However, my phone number doesn't get
to 'me', it get's to my mobile - same for my email address [of which I have
many - which can 'work' here of course: many pointers to the same object].

Having rejected these though, I thought about things like ISBN, and book
[Dewey Decimal] references, e.g., 127.56.3 in our library points to K&R
[which is always there]. Dewey references - being very similar to IP
addresses, I thought about IP addresses directly, but stuck with DNS
resolved addresses e.g., using something like:

BBC * www.bbc.co.uk //A pointer to the BBC - um?

Ok, it doesn't give me *the* BBC, but a page on the BBC's website - but you
get the idea?

The website/URL thing does have one added bonus, in that pointer to
pointers - if this analogy holds - can also be factored in i.e., say, you go
to a website and find that it's moved, and that the old pages re-direct you
to the new website, e.g., by dereferencing the initial URL the
data/'information' you get is another URL which when dereference gets you to
the website you're looking for.

Anyway, I'd be interested in hearing what others think about these
analogies, and whether they think they're 'close enough' to form an initial
hook into the function of pointers. Of course, better analogies form the
real-world would be very welcome, esp. if they allow different references to
'point' to the same object [like email addresses], and, at the same time,
can be used to get the pointer-to-pointer concept across.

I suppose that if you considered each /phone/ to be a memory location, you
could go back to using phone numbers as an analogy. I liked that one.

However, I learned pointers from an assembler manual, so I'm probably not
a very good layperson. :)
 
S

Skarmander

pemo said:
After sooo many years, I've just re-read Tracy Kidder's The Soul of a New
Machine - the guy really knows how to explain things to the lay reader [thus
the Pulitzer]! E.g., an abridged extract on addressing/memory:

". the main issue was the computer's storage system. The situation resembles
that of a region's telephone system; telephones are of no use unless they
are distinct one from the other, and an item in a computer's storage system
is of no use unless it can easily be found. The general solution resembles
the phone company's; each compartment in the computer's storage has its own
'phone number,' its own unique symbol, known as an address"

When I read that I started to think if there was some 'real-world' analogy I
could use to initially discuss *pointers* in C.
Lewis Carroll gave a very droll illustration of objects, pointers and
variables in C, in terms only *somewhat* real-world. Still, considering the
fact that he wrote it for children, and before C existed, it's quite a good
show.

Lewis said:
'You are sad,' the Knight said in an anxious tone: 'let me sing you a
song to comfort you.'

'Is it very long?' Alice asked, for she had heard a good deal of poetry
that day.

'It's long,' said the Knight, 'but very, VERY beautiful. Everybody that
hears me sing it--either it brings the TEARS into their eyes, or else--'

'Or else what?' said Alice, for the Knight had made a sudden pause.

'Or else it doesn't, you know. The name of the song is called "HADDOCKS'
EYES."'

'Oh, that's the name of the song, is it?' Alice said, trying to feel
interested.

'No, you don't understand,' the Knight said, looking a little vexed.
'That's what the name is CALLED. The name really IS "THE AGED AGED
MAN."'

'Then I ought to have said "That's what the SONG is called"?' Alice
corrected herself.

'No, you oughtn't: that's quite another thing! The SONG is called "WAYS
AND MEANS": but that's only what it's CALLED, you know!'

'Well, what IS the song, then?' said Alice, who was by this time
completely bewildered.

'I was coming to that,' the Knight said. 'The song really IS "A-SITTING
ON A GATE": and the tune's my own invention.'

One way of reading it is to substitute "object" for "song", "pointer" for
"name" and "what the variable holding it is called" for "is called":

The pointer to the object is in a variable called "HADDOCKS' EYES".
The pointer (i.e. its value) really is "THE AGED AGED MAN".
The object is in a variable called "WAYS AND MEANS".
The object really is "A-SITTING ON A GATE".

S.
 
J

John Bode

pemo wrote:

[snip]
On the telephone theme, I started thinking about mobile phones and wondered
whether I could use a person's number as a kind of pointer-to-person thing.
I also thought about email addresses. However, my phone number doesn't get
to 'me', it get's to my mobile - same for my email address [of which I have
many - which can 'work' here of course: many pointers to the same object].

[snip]


Anyway, I'd be interested in hearing what others think about these
analogies, and whether they think they're 'close enough' to form an initial
hook into the function of pointers. Of course, better analogies form the
real-world would be very welcome, esp. if they allow different references to
'point' to the same object [like email addresses], and, at the same time,
can be used to get the pointer-to-pointer concept across.

Well, there's stuff like call-forwarding; you set it up so that when
people dial number A, the call is actually sent to number B. That's
probably the closest phone-based real-world analogy I can think of.
 
K

Keith Thompson

Skarmander said:
Lewis Carroll gave a very droll illustration of objects, pointers and
variables in C, in terms only *somewhat* real-world. Still, considering the
fact that he wrote it for children, and before C existed, it's quite a good
show.



One way of reading it is to substitute "object" for "song", "pointer" for
"name" and "what the variable holding it is called" for "is called":

The pointer to the object is in a variable called "HADDOCKS' EYES".
The pointer (i.e. its value) really is "THE AGED AGED MAN".
The object is in a variable called "WAYS AND MEANS".
The object really is "A-SITTING ON A GATE".

I think Lewis Carroll (I haven't seen him posting here lately; what
happened to him?) actually got one detail wrong. The Knight should
have said "The song really IS" and then started singing it. (I think
Martin Gardner pointed this out in _The Annotated Alice_.)

Your last statement:
The object really is "A-SITTING ON A GATE".
would be correct given:
char WAYS_AND_MEANS[] = "A-SITTING ON A GATE";
 
S

Skarmander

Keith said:
I think Lewis Carroll (I haven't seen him posting here lately; what
happened to him?) actually got one detail wrong. The Knight should
have said "The song really IS" and then started singing it. (I think
Martin Gardner pointed this out in _The Annotated Alice_.)
Obviously Carroll is alluding to the possibility of multiple representations
for the same value, which C explicitly allows. I must confess I have a hard
time imagining a real-world system where a few words are equivalent to a
piece of music, but a dearth of imagination is not a proof of nonexistence.

Of course, if multiple representations are the issue here, the "really is"
should be take more liberally as "one possible representation of the value is".

The book would presumably have been cut short if the Knight had generated a
trap representation.

S.
 
K

Keith Thompson

Skarmander said:
Obviously Carroll is alluding to the possibility of multiple
representations for the same value, which C explicitly allows. I must
confess I have a hard time imagining a real-world system where a few
words are equivalent to a piece of music, but a dearth of imagination
is not a proof of nonexistence.

Of course, if multiple representations are the issue here, the "really
is" should be take more liberally as "one possible representation of
the value is".

The book would presumably have been cut short if the Knight had
generated a trap representation.

Not necessarily. Generating (or using) a trap representation merely
invokes undefined behavior. It's possible that the entire book is a
result of this. (Much more pleasant than the usual nasal demons.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top