Why do we need "->"?

Discussion in 'C Programming' started by not.here.now@gmail.com, Jul 23, 2007.

  1. Guest

    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.
     
    , Jul 23, 2007
    #1
    1. Advertising

  2. Default User Guest

    wrote:

    > 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
     
    Default User, Jul 23, 2007
    #2
    1. Advertising

  3. Guest

    On Jul 23, 2:19 am, "Default User" <> wrote:
    > wrote:
    > > 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!
     
    , Jul 23, 2007
    #3
  4. Flash Gordon Guest

    wrote, On 23/07/07 07:56:

    <snip>

    > 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
     
    Flash Gordon, Jul 24, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    Why, why, why???

    =?Utf-8?B?VGltOjouLg==?=, Jan 27, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    574
    Juan T. Llibre
    Jan 27, 2005
  2. Horace Nunley

    why why why does function not work

    Horace Nunley, Sep 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    466
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Sep 27, 2006
  3. Mr. SweatyFinger

    VWD why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    386
    =?Utf-8?B?Q2lhcmFuIE8nJycnRG9ubmVsbA==?=
    Dec 21, 2006
  4. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    917
    Mark Rae
    Dec 21, 2006
  5. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,032
    Smokey Grindel
    Dec 2, 2006
Loading...

Share This Page