Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 5th, 2004, 11:32 AM   #1
G.I.Josh
Programmer
 
G.I.Josh's Avatar
 
Join Date: Aug 2004
Location: Eastern U.S
Posts: 51
Rep Power: 5 G.I.Josh is on a distinguished road
Send a message via AIM to G.I.Josh
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!
G.I.Josh is offline   Reply With Quote
Old Aug 5th, 2004, 1:10 PM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Aug 5th, 2004, 1:18 PM   #3
G.I.Josh
Programmer
 
G.I.Josh's Avatar
 
Join Date: Aug 2004
Location: Eastern U.S
Posts: 51
Rep Power: 5 G.I.Josh is on a distinguished road
Send a message via AIM to G.I.Josh
Sure does. Thankya.
__________________
http://exponentialab.blogspot.com/ - w00t, I've started a blog!
G.I.Josh is offline   Reply With Quote
Old Aug 5th, 2004, 1:21 PM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
You're welcome
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Aug 5th, 2004, 1:46 PM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I take it the above complicated stuff simply means that statements return?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Aug 5th, 2004, 3:38 PM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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."
Infinite Recursion is offline   Reply With Quote
Old Aug 5th, 2004, 4:18 PM   #7
Kylixen
Programmer
 
Kylixen's Avatar
 
Join Date: Jun 2004
Location: SC
Posts: 60
Rep Power: 5 Kylixen is on a distinguished road
Send a message via AIM to Kylixen Send a message via MSN to Kylixen
Yea, I had something. It's gone now.
__________________
ALLOW IMAGES IN SIGNATURES NOW
Kylixen is offline   Reply With Quote
Old Aug 5th, 2004, 5:55 PM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Quote:
Originally posted by Infinite Recursion@Aug 5 2004, 08:38 PM
Complicated?

In short, expressions return values.
That's what I meant... <_<
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
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 &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:41 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC