I would not be surprised if C++ style int &y = x;
was no more than int *y = &x;
behind the scenes and every use of y
was implicitly *y
, and that this would this incur the computational expense of pointer indirection. And since the pointer is being stored anyway, there would be no memory-saving benefits here.
However, would implementing C++ style references in a manner that was direct, and more efficient than just using pointers behind the scenes, such as y
accessing x
on the stack directly the same way simply writing x
does (besides a preprocessor macro) be possible? The same way x
refers to a certain register at translation time, y
could be made to refer to the same register. If there is a struct
and a reference is declared to point to the member, could the reference just be made to refer to the register member at translation time without pointers? What would implementing this take?