Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > multiple 'new' at single line

Reply
Thread Tools

multiple 'new' at single line

 
 
Grizlyk
Guest
Posts: n/a
 
      01-01-2007
Hi, people.

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

p:(void*);
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);

 
Reply With Quote
 
 
 
 
Daniel T.
Guest
Posts: n/a
 
      01-02-2007
"Grizlyk" <(E-Mail Removed)> wrote:

> Hi, people.
>
> Can anybody explain me "multiple 'new' at single line"
> behavior. Consider:
>
> p:(void*);
> 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.
 
Reply With Quote
 
 
 
 
Grizlyk
Guest
Posts: n/a
 
      01-02-2007

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);

 
Reply With Quote
 
Daniel T.
Guest
Posts: n/a
 
      01-02-2007
"Grizlyk" <(E-Mail Removed)> 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.
 
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
resolve single line with multiple items into mutliple lines, single items ela Perl Misc 12 04-06-2009 06:47 PM
Pasting multiple lines into a single line text box Adam Plocher HTML 1 06-13-2007 05:40 PM
multiple 'new' at single line Grizlyk C++ 0 01-01-2007 06:23 PM
multiple 'new' at single line Grizlyk C++ 0 01-01-2007 06:18 PM



Advertisments