what is the execution sequence of this code?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2006
Posts: 14
Reputation: ALAZHARY is an unknown quantity at this point 
Solved Threads: 1
ALAZHARY's Avatar
ALAZHARY ALAZHARY is offline Offline
Newbie Poster

Re: what is the execution sequence of this code?

 
0
  #11
Dec 4th, 2008
Mr, Ancient Dragon
take it easy, I don't mean that, I just wanted to know how can I make it with myself.
I'd give my right arm to Improve my english
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,578
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1486
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: what is the execution sequence of this code?

 
0
  #12
Dec 4th, 2008
Like I said before, do whats in the inner-most parentheses first, then work yourself out. Once you have removed all parentheses, work the statement from left to right.

For example: a - ((b * c) / d) + e; First calculate b*c, then divide that result by d, finally subtract that result from the value of a and add e.

f = b * c;
now the equation will look like this: a - (f / d) + e

g = f / d; ===> a - g + e
Last edited by Ancient Dragon; Dec 4th, 2008 at 9:00 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 14
Reputation: ALAZHARY is an unknown quantity at this point 
Solved Threads: 1
ALAZHARY's Avatar
ALAZHARY ALAZHARY is offline Offline
Newbie Poster

Re: what is the execution sequence of this code?

 
0
  #13
Dec 4th, 2008
Thank you for you and everyone.
I'd give my right arm to Improve my english
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 147
Reputation: Laiq Ahmed will become famous soon enough Laiq Ahmed will become famous soon enough 
Solved Threads: 20
Laiq Ahmed Laiq Ahmed is offline Offline
Junior Poster

Re: what is the execution sequence of this code?

 
0
  #14
Dec 4th, 2008
Anciant Dragon has given the answer of question you've asked, you asked for What is the Execution Sequence you didn't ask How to find out the execution sequence.

Let me teach you how to find it out.
  1. void EatSpace(char* Pbuffer)
  2. {
  3. int i = 0;
  4. int j = 0;
  5. while((*(Pbuffer + i) = *(Pbuffer + j++)) != '\0')
  6. if (*(Pbuffer + i) != ' ')
  7. i++;
  8. }

when the above funciton is called, Compilers will push the PTR Puffer on stack then push the Local variables i and J on the stack.
now the interesting part.

while((*(pbuffer+i) = *(pbuffer + j++)) != 0)
assignement operator are evaluatted from right to left.
so the above code can be broken as follows
*(pbuffer + j++) the above expression is evaluated as follows
  1. take the address of pbuffer add j to its contents and derefer the complete value. increment the j for next execution

you will get some character in that case aren't you?
assign that character to lvalue which is
*(pbuffer + i) you can break the above statement now,
lets say right value calculated as 'C' you assign it to left handside so the right handside become 'C' as well which is not equal to '\0'
isn't it
always remember one thing there is still a world ahead
a more better explanation can be provided to you but the thing is that you don't know the assembly and compilers. Sometimes experts like Anciant Dragon doesn't explain the very minor details because either they are irrelevant to you or more advance so that you can't grasp them. be patient just take a hint and dig it out yourself one day you'll learn why Anciant doesn't tell you the complete story.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC