View Single Post
Old Aug 7th, 2004, 12:53 AM   #9
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
Actually executing 1+1 in the ALU would be a waste of time, as would the code that follows:

result = 1 + 2;

The reason being that we are working with constant values. Infact the compiler is going to look at this and optimize it so that result is just (re)initialized with the value of 3. Why would we want to computer otherwise constant values?

Even if you were to turn the optimizer off on this one I still believe that the code would be optimized as mentioned above since the compiler treats these explicitly as statements as opposed to expressions.

I would also like to point out that the operator

int operator+( int lhv, int rhv ){ return lhv + rhv; }

Would still treate the above code as a statement, despite the fact that the operator used to computer the value is returning a value (perhaps I am not understanding the question?)
__________________
Clifford Matthew Roche <geek@cliffordroche.com>
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote