Actually in this case (using int) passing by value is probably more efficient, since only 1 memory-read is needed instead of 2, to access the passed value.
Example (optimized using -O2):
int gl = 0;
void f1(int i)
{
gl = i + 1;
}
void f2(const int& r)
{
gl = r + 1;
}
int main()
{
f1(1);
f2(1);
}
Asm
.file "main.cpp"
.text
.p2align 2,,3
.globl __Z2f1i
.def __Z2f1i; .scl 2; .type 32; .endef
__Z2f1i:
LFB0:
pushl %ebp
LCFI0:
movl %esp, %ebp
LCFI1:
movl 8(%ebp), %eax
incl %eax
movl %eax, _gl
leave
ret
LFE0:
.p2align 2,,3
.globl __Z2f2RKi
.def __Z2f2RKi; .scl 2; .type 32; .endef
__Z2f2RKi:
LFB1:
pushl %ebp
LCFI2:
movl %esp, %ebp
LCFI3:
movl 8(%ebp), %eax
movl (%eax), %eax
incl %eax
movl %eax, _gl
leave
ret
LFE1:
.def ___main; .scl 2; .type 32; .endef
.p2align 2,,3
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
LFB2:
pushl %ebp
LCFI4:
movl %esp, %ebp
LCFI5:
andl $-16, %esp
LCFI6:
call ___main
movl $2, _gl
xorl %eax, %eax
leave
ret
LFE2:
.globl _gl
.bss
.align 4
_gl:
.space 4