A
Alex Vinokur
Compiler Green Hills C++, Version 4.0.6
--- foo.cpp ---
struct A
{
};
struct B
{
B() {}
};
struct C
{
virtual foo() {}
};
int main ()
{
A a;
B b;
C c;
return 0;
}
---------------
--- Mixed: source & asm (Fragments) ---
int main ()
0x10314 main: 7c0802a6 mflr r0
0x10318 main+0x4: 90010004 stw r0, 4(sp)
0x1031c main+0x8: 9421fff0 stwu sp, -16(sp)
{
0x10320 main+0xc: 48000d9d bl _main (0x110bc)
A a;
B b;
0x10324 main+0x10: 38610008 addi r3, sp, 8
0x10328 main+0x14: 4bfffe15 bl B::B() (0x1013c)
C c;
0x1032c main+0x18: 3861000c addi r3, sp, 0xc
0x10330 main+0x1c: 4bfffeed bl C::C() (0x1021c)
return 0;
0x10334 main+0x20: 39800000 li r12, 0
}
0x10338 main+0x24: 7d836378 mr r3, r12
0x1033c main+0x28: 80010014 lwz r0, 0x14(sp)
0x10340 main+0x2c: 7c0803a6 mtlr r0
0x10344 main+0x30: 38210010 addi sp, sp, 0x10
0x10348 main+0x34: 4e800020 blr
---------------------------------------
We can see that:
* explicit default constructor B::B() is called while building the b
object;
* implicit default constructor C::C() is called while building the c
object;
* implicit default constructor A::A() is NOT called while building the
a object.
So, A::A() is not called. Why?
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
--- foo.cpp ---
struct A
{
};
struct B
{
B() {}
};
struct C
{
virtual foo() {}
};
int main ()
{
A a;
B b;
C c;
return 0;
}
---------------
--- Mixed: source & asm (Fragments) ---
int main ()
0x10314 main: 7c0802a6 mflr r0
0x10318 main+0x4: 90010004 stw r0, 4(sp)
0x1031c main+0x8: 9421fff0 stwu sp, -16(sp)
{
0x10320 main+0xc: 48000d9d bl _main (0x110bc)
A a;
B b;
0x10324 main+0x10: 38610008 addi r3, sp, 8
0x10328 main+0x14: 4bfffe15 bl B::B() (0x1013c)
C c;
0x1032c main+0x18: 3861000c addi r3, sp, 0xc
0x10330 main+0x1c: 4bfffeed bl C::C() (0x1021c)
return 0;
0x10334 main+0x20: 39800000 li r12, 0
}
0x10338 main+0x24: 7d836378 mr r3, r12
0x1033c main+0x28: 80010014 lwz r0, 0x14(sp)
0x10340 main+0x2c: 7c0803a6 mtlr r0
0x10344 main+0x30: 38210010 addi sp, sp, 0x10
0x10348 main+0x34: 4e800020 blr
---------------------------------------
We can see that:
* explicit default constructor B::B() is called while building the b
object;
* implicit default constructor C::C() is called while building the c
object;
* implicit default constructor A::A() is NOT called while building the
a object.
So, A::A() is not called. Why?
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn