Yes, it's much harder to read and type, so you are much better off using the x->y
than (*x).y
- but other than typing efficiency, there is absolutely no difference. The compiler still needs to read the value of x
and then add the offset to y
, whether you use one form or the other [assuming there are no funny objects/classes involved that override the operator->
and operator*
respectively, of course]
There is definitely no extra object created when (*x)
is referenced. The value of the pointer is loaded into a register in the processor [1]. That's it.
Returning a reference is typically more efficient, as it returns a pointer (in disguise) to the object, rather than making a copy of the object. For objects that are bigger than the size of a pointer, this is typically a win.
[1] Yes, we can have a C++ compiler for a processor that doesn't have registers. I know of at least one processor from Rank-Xerox that I saw in about 1984, which doesn't have registers, it was a dedicated LiSP processor, and it just has a stack for LiSP objects... But they are far from common in todays world. If someone working on a processor that doesn't have registers, please don't downvote my answer simply because I don't cover that option. I'm trying to keep the answer simple.