order of execution



 DEVELOP > c-Plus-Plus > order of execution

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Wolfgang Jeltsch"
Date: 13 Aug 2003 11:08:52 AM
Object: order of execution
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
.

User: "Ron Natalie"

Title: Re: order of execution 13 Aug 2003 11:13:57 AM
"Wolfgang Jeltsch" <jeltsch@tu-cottbus.de> wrote in message news:bhdnq7$118pae$1@ID-77306.news.uni-berlin.de...

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.
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER