Possible Duplicate:
Why does C have a distinction between -> and .?
Compilers are smart enough to know if the left side operand is a pointer or a reference. Why are there two different operators (. and ->) for member access?
Is it to make the indirection explicit? For legibility? Was there something about the available hardware when C was designed that made a strong case for those operations to be easily distinguished when reading source code?
I've read about it simply being a shorthand syntax for (*ptr).member
, but is ptr.member
ever valid when ptr is a pointer? Why can't ptr.member
"just work" as ptr->member
if ptr is a pointer?