Im an old, emphasis on old, K&R guy, so I am very well versed in accessing members of structures, unions, and now classes with "." notation vs "->" notation. I was asked this morning "why the difference?" My answer started with "That's easy," and then every instance that I could come up with I ended up deciding that a modern compiler could easily overcome the issues.
So, given a structure or class foo with a single member "a"
I understand that
struct foo *pfoo, afoo;
pfoo=&afoo;
pfoo->a would be the appropriate call
OR
struct foo afoo;
afoo.a would be the appropriate call
but why are they separate. In case 1, why can't the compiler sort out pfoo.a or in the second afoo->a. There must be a case where this behavior would be unacceptable, but I am trying to fathom what it is.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.