I'm not good at reading assembler code, but the way I see your example, when in main:
- 1000 is loaded into a register
- 1 is substracted,
- the address of "a" is loaded and
- the output operator is called before the
- jump back to the beginning of the loop.
I don't see a call to fire
or show
. It keeps the implementation for show, but it is not used. That is correct because it has external linkage.
If you put everything in an anonymous namespace, the implementation can be omitted.
Could you put your reasoning with the assembler code in your question? For reference, here is the generated assembler code from the provides link:
.LC0:
.string "a"
A::show():
movl $1, %edx
movl $.LC0, %esi
movl std::cout, %edi
jmp std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)
main:
pushq %rbx
movl $1000, %ebx
.L3:
movl $1, %edx
movl $.LC0, %esi
movl std::cout, %edi
call std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)
subl $1, %ebx
jne .L3
xorl %eax, %eax
popq %rbx
ret
subq $8, %rsp
movl std::__ioinit, %edi
call std::ios_base::Init::Init()
movl $__dso_handle, %edx
movl std::__ioinit, %esi
movl std::ios_base::Init::~Init(), %edi
addq $8, %rsp
jmp __cxa_atexit