I rarely see a transition by const value. Is this useful, or will the compiler detect a constant when passing by value?
Passing const values ββdoes not really exist. When you go through a value, you cannot change the value so that the changes are visible outside the subroutine. This is because when you pass by value, a copy is made from the original value and this copy is used in the function.
The const reference takes up too much space. Can I just skip past the cost? Can modern compilers optimize it so as not to sacrifice performance?
Passing by ( const ) link does not match passing by value. When you pass by reference, the value is NOT copied, the memory location is simply provided, and you can "change" (indirectly) the value that you pass by reference.
Take for example the following:
void byValue(int x) { x += 1 } void byRef(int &x) { x += 1 }
Use the constant as much as possible.
Passing const , where necessary, is always a good idea. This helps the readability of the code, allows others to know what will happen to the values ββthat they pass to the method, and helps the compiler catch any errors that may occur when the value changes inside the method.
There is no performance difference between passing by reference and pointer.
Negligible amount, if any. The compiler will take care of the details here. This saves you the effort of creating a pointer, and it beautifully plays it out for you.
If the size does not exceed a word, go to the value.
As Mark points out, you do this if the value is less than a pointer. Pointers have different sizes on 32-bit and 64-bit systems (hence the name), and therefore this is really at your discretion. I am a fan of missing pointers for almost everyone except primitive types ( char , int8_t , int16_t , float , etc.), but this is just my opinion.