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

  • Thread starter Dennis Yurichev
  • Start date

D

Dennis Yurichev

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?
 
Ad

Advertisements

B

BGB

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

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

Ask a Question

Top