multiple 'new' at single line

Discussion in 'C++' started by Grizlyk, Jan 1, 2007.

  1. Grizlyk

    Grizlyk Guest

    Hi, people.

    Can anybody explain me "multiple 'new' at single line"
    behavior. Consider:

    p::p(void*);
    p::p(void*,void*);

    new A( p(new B), p( new C(p(new D), p(new E)) ), p(new F));

    Will it be either

    1.
    new F p(*)
    new E p(*)
    new D p(*)
    new C p(*)
    new B p(*)
    new A

    and
    2.
    new B p(*)
    new D p(*)
    new E p(*)
    new C p(*)
    new F p(*)
    new A p(*)

    or
    3.

    new E
    new D
    new F
    new C
    new B
    p(*)
    p(*)
    p(*)
    p(*)
    p(*)
    new A

    Does C++ guarantee that never can be like upper
    case 3 (more than one "new" befor "p(*)").

    Do we need to create temp storages:

    const p tmp1(new F);
    const p tmp2(new E);
    const p tmp3(new D);
    const p tmp4(new C(tmp3,tmp2));
    const p tmp5(new B);
    new A(tmp5,tmp4,tmp1);
     
    Grizlyk, Jan 1, 2007
    #1
    1. Advertising

  2. Grizlyk

    Daniel T. Guest

    "Grizlyk" <> wrote:

    > Hi, people.
    >
    > Can anybody explain me "multiple 'new' at single line"
    > behavior. Consider:
    >
    > p::p(void*);
    > p::p(void*,void*);
    >
    > new A( p(new B), p( new C(p(new D), p(new E)) ), p(new F));


    The only order guarantee you have with the above is that the B, D, E and
    F object will be created first (in any order); that C will be created
    after D and E; and that B through F will all be created before A.
    Outside of that, there are no order guarantees.
     
    Daniel T., Jan 2, 2007
    #2
    1. Advertising

  3. Grizlyk

    Grizlyk Guest

    Daniel T. wrote:

    > > new A( p(new B), p( new C(p(new D), p(new E)) ), p(new F));

    >
    > The only order guarantee you have with the above is that the B, D, E and
    > F object will be created first (in any order); that C will be created
    > after D and E; and that B through F will all be created before A.
    > Outside of that, there are no order guarantees.


    I do not understand, can be optimized or no like this:

    compiled_tmp1=new D,
    compiled_tmp2=new E,
    compiled_p1=p(compiled_tmp1),
    compiled_p2=p(compiled_tmp2),
    new c(compiled_p1, compiled_p2);
     
    Grizlyk, Jan 2, 2007
    #3
  4. Grizlyk

    Daniel T. Guest

    "Grizlyk" <> wrote:
    > Daniel T. wrote:
    >
    > > > new A( p(new B), p( new C(p(new D), p(new E)) ), p(new F));

    > >
    > > The only order guarantee you have with the above is that the B, D, E and
    > > F object will be created first (in any order); that C will be created
    > > after D and E; and that B through F will all be created before A.
    > > Outside of that, there are no order guarantees.

    >
    > I do not understand, can be optimized or no like this:
    >
    > compiled_tmp1=new D,
    > compiled_tmp2=new E,
    > compiled_p1=p(compiled_tmp1),
    > compiled_p2=p(compiled_tmp2),
    > new c(compiled_p1, compiled_p2);


    Yes, it can be done like that. It can also be done like this:

    compiled_tmp1=new D,
    compiled_p1=p(compiled_tmp1),
    compiled_tmp2=new E,
    compiled_p2=p(compiled_tmp2),
    new c(compiled_p1, compiled_p2);

    or like this:

    compiled_tmp2=new E,
    compiled_p2=p(compiled_tmp2),
    compiled_tmp1=new D,
    compiled_p1=p(compiled_tmp1),
    new c(compiled_p1, compiled_p2);

    or like this:

    compiled_tmp2=new E,
    compiled_tmp1=new D,
    compiled_p1=p(compiled_tmp1),
    compiled_p2=p(compiled_tmp2),
    new c(compiled_p1, compiled_p2);

    Or any of a few other orders I expect.
     
    Daniel T., Jan 2, 2007
    #4
    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. Replies:
    4
    Views:
    956
    M.E.Farmer
    Feb 13, 2005
  2. Grizlyk

    multiple 'new' at single line

    Grizlyk, Jan 1, 2007, in forum: C++
    Replies:
    0
    Views:
    257
    Grizlyk
    Jan 1, 2007
  3. Grizlyk

    multiple 'new' at single line

    Grizlyk, Jan 1, 2007, in forum: C++
    Replies:
    0
    Views:
    279
    Grizlyk
    Jan 1, 2007
  4. Adam Plocher
    Replies:
    1
    Views:
    852
    Jonathan N. Little
    Jun 13, 2007
  5. ela
    Replies:
    12
    Views:
    349
    Uri Guttman
    Apr 6, 2009
Loading...

Share This Page