This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
execution order
- From: KÃvesdi GyÃrgy <kgy at deverto dot hu>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 24 Sep 2007 10:59:00 +0200
- Subject: execution order
Hi,
I use avr-g++ 4.2.1, but I tried it on Intel platform too, with the same
result.
Let's see the following code:
int f1()
{
MyClass c;
return f2();
}
The following code is generated:
- Constructor of MyClass is called
- f2() is called
- Destructor of MyClass is called.
It is as expected.
But the following source:
int variable;
int f1()
{
MyClass c;
return variable;
}
The generated code depends on the optimization level. If the optimization is
not used, it is as expected (as in the previous example):
- Constructor of MyClass
- Reading the variable
- Destructor of MyClass
If any optimization is used, the following code is generated:
- Constructor of MyClass
- Destructor of MyClass
- Reading the variable
which is not as expected. I think that this execution order is not correct.
Is it a gcc-problem or I misunderstand something?
Regards
K. Gy.