Last active
December 14, 2015 05:49
-
-
Save kinoshita-lab/5038090 to your computer and use it in GitHub Desktop.
Comparison between call by reference and call by value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The Code: | |
int add_ref(const int& a, const int& b) | |
{ | |
return a + b; | |
} | |
int add_value(const int a, const int b) | |
{ | |
return a + b; | |
} | |
---------------------------------------------------------------------------- | |
Compile with: | |
clang++ -O3 -S -mllvm --x86-asm-syntax=intel hoge.cpp -o hoge.intel.s | |
where | |
clang++ -v | |
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn) | |
Target: x86_64-apple-darwin12.2.0 | |
---------------------------------------------------------------------------- | |
The Result (simpilified): | |
__Z7add_refRKiS0_: ## @_Z7add_refRKiS0_ | |
push RBP | |
mov RBP, RSP | |
mov EAX, DWORD PTR [RSI] | |
add EAX, DWORD PTR [RDI] | |
pop RBP | |
ret | |
__Z9add_valueii: ## @_Z9add_valueii | |
push RBP | |
mov RBP, RSP | |
add EDI, ESI | |
mov EAX, EDI | |
pop RBP | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment