![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
Hello. I know what both statements and expressions are, but it seems like from the processor's point of view there isn't much difference. The book I'm reading sais that statements are instructions that can be executed. Would not 1+1, an expression, be executed in the alu? Would that not make it a statement?
__________________
http://exponentialab.blogspot.com/ - w00t, I've started a blog! |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
Variable declarations and initializations, etc are statements, as are the basic language structures like conditionals and loops.
Expressions are statements that produce a result that can be used as part of another statement. Method calls, object allocations, and, of course, mathematical expressions are examples of expressions. Hopefully, that clears it up for you.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
Programmer
|
Sure does. Thankya.
__________________
http://exponentialab.blogspot.com/ - w00t, I've started a blog! |
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() ![]() |
You're welcome
![]()
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I take it the above complicated stuff simply means that statements return?
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
Complicated?
In short, expressions return values.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#7 |
|
Programmer
|
Yea, I had something. It's gone now.
__________________
ALLOW IMAGES IN SIGNATURES NOW |
|
|
|
|
|
#8 | |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Quote:
|
|
|
|
|
|
|
#9 |
|
Expert Programmer
|
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|