Connecting Tech Pros Worldwide Forums | Help | Site Map

Why do we need "->"?

not.here.now@gmail.com
Guest
 
Posts: n/a
#1: Jul 23 '07
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.


Default User
Guest
 
Posts: n/a
#2: Jul 23 '07

re: Why do we need "->"?


not.here.now@gmail.com wrote:
Quote:
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
not.here.now@gmail.com
Guest
 
Posts: n/a
#3: Jul 23 '07

re: Why do we need "->"?


On Jul 23, 2:19 am, "Default User" <defaultuse...@yahoo.comwrote:
Quote:
not.here....@gmail.com wrote:
Quote:
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
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!

Flash Gordon
Guest
 
Posts: n/a
#4: Jul 24 '07

re: Why do we need "->"?


not.here.now@gmail.com wrote, On 23/07/07 07:56:

<snip>
Quote:
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.
--
Flash Gordon
Closed Thread