order of execution

Discussion in 'C++' started by Wolfgang Jeltsch, Aug 13, 2003.

  1. 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
     
    Wolfgang Jeltsch, Aug 13, 2003
    #1
    1. Advertising

  2. Wolfgang Jeltsch

    Ron Natalie Guest

    "Wolfgang Jeltsch" <> wrote in message news:bhdnq7$118pae$-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.
     
    Ron Natalie, Aug 13, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. priya
    Replies:
    0
    Views:
    1,244
    priya
    Oct 3, 2005
  2. =?Utf-8?B?QmlsbCBCb3Jn?=

    Execution order of PageLoad for user controls

    =?Utf-8?B?QmlsbCBCb3Jn?=, Mar 6, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,373
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Mar 6, 2004
  3. Bijoy Naick

    Execution order of Validation Controls

    Bijoy Naick, Jun 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,971
    Martin Marinov
    Jun 8, 2004
  4. John Saunders

    Re: A question about order of execution?

    John Saunders, Jul 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    367
    S. Justin Gengo
    Jul 15, 2004
  5. S. Justin Gengo

    Re: A question about order of execution?

    S. Justin Gengo, Jul 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,064
    S. Justin Gengo
    Jul 15, 2004
Loading...

Share This Page