execution order

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux