Quote:Original post by Anonymous Poster
btw every time you use a reference, the compiler internally uses a pointer.
that means every call by reference is some kind of workaround so that you don't have to use the dereference-operator.
Not really. First of all, the compiler does not internally use a pointer: both pointers and references (which are C++ concepts) are translated to a lower-level implementation, which involves memory addressing machine code in the case of pointers and sometimes in the case of references as well. While the use of pointers (or unary &) forces the compiler to place the variable in memory and manipulate its address, a referenced variable can be placed in a register if its use is local. Consider:
bool a;while(a) { someInlineFunctionRef(a); }while(a) { someInlineFunctionPtr(&a); }
The second loop forces a to be placed in normal memory, so its address can be taken. The first loop does not prevent the compiler from placing a in a register.
Also, in the case of const int & arguments, a compiler would be able to safely pass the integer by value instead of reference (although such behavior might be prevented by the ABI).
References also allow you to pass temporary values by reference instead of by value. Another advantage is that you don't need to check for NULL references.