Why do we need "->"?

N

not.here.now

I often change my mind (sometimes back and forth several times) about
whether a given variable should contain a pointer to a structure or
the structure itself, and generally each time I'll have to change
several instances of "." to "->" or vice versa, in the related code.
But the compiler knows when something is a pointer, why can't it let
me write "." in every case and automatically dereference as many times
as necessary?

I've read dmr's article on the history and development of C, and he
talks about a time when "foo->bar" would compile almost regardless of
the type of "foo", with "->bar" just meaning "add a certain offset and
dereference a value of a given type". (Does this mean it wasn't
possible to use the same member name in more than one structure type,
at least for members at different offsets?) Anyway, though, if it was
just a question of backwards compatibility at some point, they could
have deprecated "->" while adding new functionality to ".". So: Is
there a good reason that I'm missing, or is it just that somebody
thought it was a good idea for the programmer to have to make the
difference between pointers and values explicit on every reference?
Because it seems like syntactic salt to me.
 
D

Default User

I often change my mind (sometimes back and forth several times) about
whether a given variable should contain a pointer to a structure or
the structure itself, and generally each time I'll have to change
several instances of "." to "->" or vice versa, in the related code.
But the compiler knows when something is a pointer, why can't it let
me write "." in every case and automatically dereference as many times
as necessary?

We just had a long thread on this, look it up.



Brian
 
N

not.here.now

We just had a long thread on this, look it up.

Brian

I was puzzled when I saw this, because a short while ago I checked for
such, without success. But I looked again, and found the thread...
started by me. I thought Google Groups hadn't posted my message, but
in fact it was only delayed by a few hours. Apologies!
 
F

Flash Gordon

(e-mail address removed) wrote, On 23/07/07 07:56:

I was puzzled when I saw this, because a short while ago I checked for
such, without success. But I looked again, and found the thread...
started by me. I thought Google Groups hadn't posted my message, but
in fact it was only delayed by a few hours. Apologies!

With news groups you have to wait at least a day before assuming things
have gone wrong.
 

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

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top