Last active
December 18, 2015 09:59
-
-
Save kinoshita-lab/5764901 to your computer and use it in GitHub Desktop.
compare normal method within a namespace, and static class method.
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
in unko.h | |
------------------- | |
class StaticClass | |
{ | |
public: | |
static int method() { | |
return 1; | |
} | |
}; | |
namespace NamespaceQuasiStaticClass | |
{ | |
int method() { | |
return 1; | |
} | |
} | |
in unko.cpp | |
------------------- | |
#include <cstdio> | |
#include "unko.h" | |
void callStatic() | |
{ | |
printf("%d\n", StaticClass::method()); | |
} | |
void callNamespace() | |
{ | |
printf("%d\n", NamespaceQuasiStaticClass::method()); | |
} | |
------------------- | |
compile w/ | |
clang++ -c -Os -S -mllvm --x86-asm-syntax=intel unko.cpp -o unko.s | |
------------------- | |
the result(simplified) | |
__Z10callStaticv: ## @_Z10callStaticv | |
push RBP | |
mov RBP, RSP | |
lea RDI, QWORD PTR [RIP + L_.str] | |
mov ESI, 1 | |
xor AL, AL | |
pop RBP | |
jmp _printf ## TAILCALL | |
__Z13callNamespacev: ## @_Z13callNamespacev | |
push RBP | |
mov RBP, RSP | |
lea RDI, QWORD PTR [RIP + L_.str] | |
mov ESI, 1 | |
xor AL, AL | |
pop RBP | |
jmp _printf ## TAILCALL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment