troubleshooting Question

why "." vs "->"

Avatar of rickhill11
rickhill11 asked on
CC++
23 Comments5 Solutions246 ViewsLast Modified:
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.
ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 5 Answers and 23 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 5 Answers and 23 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004