hi list,

I'm using g++ to compile my project under linux. When checking c++
object files, I have a question about it.

there is a example:
------------------------------
class A {
public:
  A();
  A(int _i);
  ~A();
  void hello();
        
private:
  int i;
};

A::A()
{
  i = 0;
}

A::A(int _i)
{
  i = _i;
}

A::~A()
{
  i = 2;
}

void A::hello()
{
  i = 1;
}
--------------------------------

I compile it by using g++ 4.3.2 under Ubuntu 8.04, run 'objdump -dCr
test.o', and get the result:

--------------------------------
test.o:     file format elf32-i386

Disassembly of section .text:

00000000 <A::A()>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   8b 45 08                mov    0x8(%ebp),%eax
   6:   c7 00 00 00 00 00       movl   $0x0,(%eax)
   c:   5d                      pop    %ebp
   d:   c3                      ret

0000000e <A::A()>:
   e:   55                      push   %ebp
   f:   89 e5                   mov    %esp,%ebp
  11:   8b 45 08                mov    0x8(%ebp),%eax
  14:   c7 00 00 00 00 00       movl   $0x0,(%eax)
  1a:   5d                      pop    %ebp
  1b:   c3                      ret

0000001c <A::A(int)>:
  1c:   55                      push   %ebp
  1d:   89 e5                   mov    %esp,%ebp
  1f:   8b 55 08                mov    0x8(%ebp),%edx
  22:   8b 45 0c                mov    0xc(%ebp),%eax
  25:   89 02                   mov    %eax,(%edx)
  27:   5d                      pop    %ebp
  28:   c3                      ret
  29:   90                      nop

0000002a <A::A(int)>:
  2a:   55                      push   %ebp
  2b:   89 e5                   mov    %esp,%ebp
  2d:   8b 55 08                mov    0x8(%ebp),%edx
  30:   8b 45 0c                mov    0xc(%ebp),%eax
  33:   89 02                   mov    %eax,(%edx)
  35:   5d                      pop    %ebp
  36:   c3                      ret
  37:   90                      nop

00000038 <A::~A()>:
  38:   55                      push   %ebp
  39:   89 e5                   mov    %esp,%ebp
  3b:   8b 45 08                mov    0x8(%ebp),%eax
  3e:   c7 00 02 00 00 00       movl   $0x2,(%eax)
  44:   5d                      pop    %ebp
  45:   c3                      ret

00000046 <A::~A()>:
  46:   55                      push   %ebp
  47:   89 e5                   mov    %esp,%ebp
  49:   8b 45 08                mov    0x8(%ebp),%eax
  4c:   c7 00 02 00 00 00       movl   $0x2,(%eax)
  52:   5d                      pop    %ebp
  53:   c3                      ret

00000054 <A::hello()>:
  54:   55                      push   %ebp
  55:   89 e5                   mov    %esp,%ebp
  57:   8b 45 08                mov    0x8(%ebp),%eax
  5a:   c7 00 01 00 00 00       movl   $0x1,(%eax)
  60:   5d                      pop    %ebp
  61:   c3                      ret
----------------------

my question is why every constructor/destructor of class A have a
couple of same code blocks in the object file?

best regrads,
dragchan

Reply via email to