EDIT EDIT EDIT EDIT EDITE DITE ESJREGJHGWKHWGWG: I'm stupid.
Okay. I was also interested in this, so I did a little debugging.
void a(int& x) { x += 2; }
int main() { int b = 2; a(b); }
Disassembly:
Code:
// main()
00401088 |. C745 FC 020000>MOV DWORD PTR SS:[EBP-4],2
0040108F |. 8D45 FC LEA EAX,DWORD PTR SS:[EBP-4]
00401092 |. 50 PUSH EAX
00401093 |. E8 77FFFFFF CALL test.0040100F
// a()
00401038 |. 8B45 08 MOV EAX,DWORD PTR SS:[EBP+8]
0040103B |. 8B08 MOV ECX,DWORD PTR DS:[EAX]
0040103D |. 83C1 02 ADD ECX,2
00401040 |. 8B55 08 MOV EDX,DWORD PTR SS:[EBP+8]
00401043 |. 890A MOV DWORD PTR DS:[EDX],ECX
void a(int* x) { *x += 2; }
int main() { int b = 2; a(&b); }
Disassembly:
Code:
// main()
00401078 |. C745 FC 020000>MOV DWORD PTR SS:[EBP-4],2
0040107F |. 8D45 FC LEA EAX,DWORD PTR SS:[EBP-4]
00401082 |. 50 PUSH EAX
00401083 |. E8 87FFFFFF CALL test.0040100F
// a()
00401038 |. 8B45 08 MOV EAX,DWORD PTR SS:[EBP+8]
0040103B |. 8B08 MOV ECX,DWORD PTR DS:[EAX]
0040103D |. 83C1 02 ADD ECX,2
00401040 |. 8B55 08 MOV EDX,DWORD PTR SS:[EBP+8]
00401043 |. 890A MOV DWORD PTR DS:[EDX],ECX
So, my findings conclude that they are exactly the same, and that I didn't accidentally copy and paste the same thing twice. Both simply push a "reference" (the effective address) of our number 2 and modify that accordingly. The pass-by-refeference vs. faked pointer stuff seems to be only a higher level implementation to let you use '.' and not derenference the pointer on every use. I could and probably am wrong in saying this, and my compile (VC++) might have made bad assumptions. I don't know.
Edit: Dearly sorry for the edit's but gcc gives the same results. And compiles the pass by reference. "meh"