This is the mail archive of the gcc-help@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]
Other format: [Raw text]

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.


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