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