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. Advertisements

  2. Dennis Yurichev

    BGB Guest

    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. Advertisements

  3. Dennis Yurichev, Dec 6, 2012
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.