Created
June 12, 2013 13:43
-
-
Save kinoshita-lab/5765356 to your computer and use it in GitHub Desktop.
compare normal method within a namespace, and static class method(again),
this time i added both class value and global 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
in unko.h | |
------------------- | |
class StaticClass | |
{ | |
public: | |
static int counter(); | |
static int value; | |
}; | |
namespace NamespaceQuasiStaticClass | |
{ | |
int method(); | |
extern int value; | |
} | |
in unko.cpp | |
------------------- | |
#include "unko.h" | |
int StaticClass::value = 0; | |
int StaticClass::counter() | |
{ | |
value++; | |
return value; | |
} | |
namespace NamespaceQuasiStaticClass | |
{ | |
int value = 0; | |
int method() | |
{ | |
value++; | |
return value; | |
} | |
} | |
------------------- | |
compile w/ | |
clang++ -c -Os -S -mllvm --x86-asm-syntax=intel unko.cpp -o unko.s | |
------------------- | |
the result(simplified) | |
__ZN11StaticClass7counterEv: ## @_ZN11StaticClass7counterEv | |
push RBP | |
mov RBP, RSP | |
mov EAX, DWORD PTR [RIP + __ZN11StaticClass5valueE] | |
inc EAX | |
mov DWORD PTR [RIP + __ZN11StaticClass5valueE], EAX | |
pop RBP | |
ret | |
__ZN25NamespaceQuasiStaticClass6methodEv: ## @_ZN25NamespaceQuasiStaticClass6methodEv | |
push RBP | |
mov RBP, RSP | |
mov EAX, DWORD PTR [RIP + __ZN25NamespaceQuasiStaticClass5valueE] | |
inc EAX | |
mov DWORD PTR [RIP + __ZN25NamespaceQuasiStaticClass5valueE], EAX | |
pop RBP | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment