Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > order of execution

Reply
Thread Tools

order of execution

 
 
Wolfgang Jeltsch
Guest
Posts: n/a
 
      08-13-2003
Hello,

am I right that in
p = new SomeClass(p)
the newly constructed object is initialized and therefore the p in the
brackets is used before the assignment of the new pointer to p takes place?

Is it generally guaranteed that all side effects of an expression have taken
place before the expression's result is used as an operator argument or
function parameter?

Wolfgang
 
Reply With Quote
 
 
 
 
Ron Natalie
Guest
Posts: n/a
 
      08-13-2003

"Wolfgang Jeltsch" <> wrote in message news:bhdnq7$118pae$...
> Hello,
>
> am I right that in
> p = new SomeClass(p)
> the newly constructed object is initialized and therefore the p in the
> brackets is used before the assignment of the new pointer to p takes place?


Yes.

>
> Is it generally guaranteed that all side effects of an expression have taken
> place before the expression's result is used as an operator argument or
> function parameter?


A sequence point (which means that the side effects will have been applied)
occurs when a function is called and again when it returns. As a result the
answer to your question is yes.

However, be careful of the following sort of thing:

p = f(expression_a) + g(expression_b);

expression_a and expression_b are guaranteed to be consistant before their use as
a parameter in the respective functions, but it's possible that both expressions are
evaluated before either function is called (or they could be defered to the point of the
call). This makes expressions like:
p = f(++a) + g(++a)
undefined behavior, because it's possible that ++a is executed before the sequence
points inherent in the function calls.


 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
private data stashed in local/global execution context of PyEval_EvalCode disappears down the execution stack sndive@gmail.com Python 9 11-14-2007 10:31 PM
doubt in FLI Program and order of execution priya VHDL 0 10-03-2005 12:55 PM
Re: A question about order of execution? John Saunders ASP .Net 2 07-15-2004 06:44 PM
Execution order of Validation Controls Bijoy Naick ASP .Net 1 06-08-2004 04:31 PM
Execution order of PageLoad for user controls =?Utf-8?B?QmlsbCBCb3Jn?= ASP .Net 2 03-06-2004 03:01 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57