Skip to content

Instantly share code, notes, and snippets.

@kinoshita-lab
Last active December 18, 2015 09:59
Show Gist options
  • Save kinoshita-lab/5764901 to your computer and use it in GitHub Desktop.
Save kinoshita-lab/5764901 to your computer and use it in GitHub Desktop.
compare normal method within a namespace, and static class method.
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