This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Default constructors & arrays


Hi,

Can somebody clarify to me why egcs generates different code for
built-in int and defined Int class? I though giving an empty default
constructor would get rid of constructor call .. am I missing
something well known?


Thanks, Igor


#define INT

#ifdef INT

class Int {
private:
  int i;
public:
   Int() {}
   Int( int I ) : i(I) {}
  ~Int() {}

  Int& operator = ( int I ) { i = I; return *this; }
};

#endif

int main() {

#ifdef INT
  Int a[10000];
#else
  int a[10000];
#endif

  a[0] = 1;

  return 0;
}

compiled with -O16 -felide-constructors

for "int" case:

main:
        pushl %ebp
        movl %esp,%ebp
        subl $40000,%esp
        movl $1,-40000(%ebp)
        movl %ebp,%esp
        xorl %eax,%eax
        popl %ebp
        ret

for "Int" case:

main:
        pushl %ebp
        movl %esp,%ebp
        subl $40000,%esp
        movl $9999,%eax
        .align 4
.L15:
        subl $1,%eax
        jnc .L15
        movl $1,-40000(%ebp)
        leal -40000(%ebp),%edx
        movl %ebp,%eax
        cmpl %ebp,%edx
        je .L20
        .align 4
.L23:
        addl $-4,%eax
        cmpl %eax,%edx
        jne .L23
.L20:
        movl %ebp,%esp
        xorl %eax,%eax
        popl %ebp
        ret


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]