Skip to content

Instantly share code, notes, and snippets.

@kinoshita-lab
Created June 12, 2013 13:43
Show Gist options
  • Save kinoshita-lab/5765356 to your computer and use it in GitHub Desktop.
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.
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