2 ms·
Surely then, passing an object by reference is just passing the reference to the reference to the object by value? It's references all the way down! To take i
by NickPollard 16y ago
Surely then, passing an object by reference is just passing the reference to the reference to the object by value?
It's references all the way down!
To take it to a lower level, we're passing a string of binary digits to the function. This happens either through a register, or through the stack. The function then has to decide what to do with it - either it uses it as the value of something, or it takes it as a memory address and derefences it. It can then repeat this last step for as many levels of indirection as it wishes.
It's clearer in C.
void f(struct object a); // Pass struct by value
void f_(struct object* a); // Pass struct by reference, pass reference by value
void f__(struct object a); // Pass reference to struct by reference, pass reference to reference to struct by value
void f________struct object a); // What the hell are you doing? You've created a monstrosity