Created
September 14, 2015 18:44
-
-
Save ruslo/f0bb18c73f3d08ea544b to your computer and use it in GitHub Desktop.
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
> cat foo.cpp | |
class A { | |
public: | |
A() { | |
a_[0] = 0x1; | |
a_[1] = 0x15; | |
a_[2] = 0x34; | |
} | |
int result(int value) const { | |
return a_[value]; | |
} | |
private: | |
int a_[3]; | |
}; | |
class B { | |
public: | |
B() { | |
} | |
int result(int value) const { | |
switch(value) { | |
case 0: return 0x1; | |
case 1: return 0x15; | |
case 2: return 0x34; | |
} | |
} | |
}; | |
int foo(const A& a) { | |
return a.result(2) + 0x42; | |
} | |
int boo(const B& b) { | |
return b.result(2) + 0x42; | |
} | |
> clang++ -O3 ./foo.cpp -o foo -c | |
> otool -vt ./foo | |
__Z3fooRK1A: | |
0000000000000000 pushq %rbp | |
0000000000000001 movq %rsp, %rbp | |
0000000000000004 movl 0x8(%rdi), %eax | |
0000000000000007 addl $0x42, %eax | |
000000000000000a popq %rbp | |
000000000000000b retq | |
__Z3booRK1B: | |
0000000000000010 pushq %rbp | |
0000000000000011 movq %rsp, %rbp | |
0000000000000014 movl $0x76, %eax | |
0000000000000019 popq %rbp | |
000000000000001a retq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment