Re: optimization options not working

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

 



rohitgeek wrote:
mentioned by Ian too, i get what i expect. But why does optimizer does so?

because it can with respect to the semantics of the compiled language.
Your statements assign values to local variables.
There is no side effect.
The values you assign are not used later on.
So they are completely useless. Computing them or not won't change
the semantics of your program. At all.
It's cool that gcc finds that out for cases where your code actually
does something, where optimization is useful. No?

Where is the assembly or data gone when doing the earlier way, because if we

You write programs in C, not in assembly language. The C compiler
can compile the way it wants as long as the C semantics is
respected.

put some data into registers and done some manipulations, then where are

This is what you don't understand I guess. Your program doesn't "put some data into
registers and [does] some manipulations." Your program assigns values to C variables.
This is another world.
C is not assembly language.

So in short, as others said, if you want the code to stay there
after optimization, be sure it does real stuff, like returning
the computed value. The computed value has to "escape" the local
scope for it to be "respected" by the optimization.

My .2 euros.

[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