Why does C have both . and -> for addressing struct members?

Discussion in 'C++' started by Dennis Yurichev, Dec 6, 2012.

  1. Hi.

    Why does C have both . and -> for addressing struct members?

    Is it possible to have such modified language syntax, where we can take
    p as a pointer to struct and get a struct member's value just as p.value?
     
    Dennis Yurichev, Dec 6, 2012
    #1
    1. Advertising

  2. Dennis Yurichev

    BGB Guest

    On 12/5/2012 11:00 PM, Dennis Yurichev wrote:
    > Hi.
    >
    > Why does C have both . and -> for addressing struct members?
    >
    > Is it possible to have such modified language syntax, where we can take
    > p as a pointer to struct and get a struct member's value just as p.value?
    >


    probably mostly for historical reasons?...

    like, early on, there was a time when C was mostly untyped, and when
    structs worked a bit differently than they do now. the different
    operators were probably needed mostly for the compiler to know how to go
    about accessing the struct member or similar.

    since then, there isn't really a strong reason that I can see (the
    compiler could easily enough figure it out on its own). some compilers
    also make them essentially interchangeable as well, and I suspect the
    others may just check to make sure that the programmer used the right one.


    then again, a person can also wonder the reasons for the existence of .*
    and ->* in C++ as well, but oh well...
     
    BGB, Dec 6, 2012
    #2
    1. Advertising

  3. Dennis Yurichev, Dec 6, 2012
    #3
    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. raj
    Replies:
    23
    Views:
    668
  2. Chris Fogelklou
    Replies:
    36
    Views:
    1,391
    Chris Fogelklou
    Apr 20, 2004
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,999
    Smokey Grindel
    Dec 2, 2006
  4. GS
    Replies:
    19
    Views:
    1,623
    Gordon Burditt
    Dec 15, 2004
  5. John Reye
    Replies:
    28
    Views:
    1,377
    Tim Rentsch
    May 8, 2012
Loading...

Share This Page