Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Order of de...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 39 Topic 9813 of 9984
Post > Topic >>

Re: Order of destruct of local variables

by Alberto Ganesh Barbati <AlbertoBarbati@[EMAIL PROTECTED] > Jul 21, 2008 at 11:15 PM

Thomas Lehmann ha scritto:
> On 21 Jul., 12:31, rkld...@[EMAIL PROTECTED]
 wrote:
>>
>> I think the standard has reference only to the order of destruction of
>> static local variables, but not so much on the order for local
>> variables with auto storage.
> 
> Don't rely on any order! This is the best choice for you to avoid
> running into undefined behaviour!

That would be very unwise. The order of destruction is guaranteed, so it
good to be aware of it and I see nothing wrong in relying on it.

> running into undefined behaviour! If you need ordered deletion than
> write a little tool class for that! I have managed it this way:
> 
> int main()
> {
>      AutoCleanup autoCleanup;
>      AB* ab = autoCleanup(new AB);
>      AC* ac = autoCleanup(new AC);
>      return 0;
> }//main
> 
> "ac" will be destroyed before "ab"!
> 

Why making things more complex that they are? What's the advantage of
this code with the more simple and obvious:

  int main()
  {
       AB ab;
       AC ac;
       return 0;
  } // "ac" will be destroyed before "ab"!

?

Just my opinion,

Ganesh

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 39 Posts in Topic:
Order of destruct of local variables
rkldabs@[EMAIL PROTECTED]  2008-07-21 04:31:10 
Re: Order of destruct of local variables
Greg Herlihy <greghe@[  2008-07-21 14:36:23 
Re: Order of destruct of local variables
Alberto Ganesh Barbati &l  2008-07-21 15:16:29 
Re: Order of destruct of local variables
LR <lruss@[EMAIL PROTE  2008-07-21 15:19:25 
Re: Order of destruct of local variables
Thomas Maeder <maeder@  2008-07-21 15:19:12 
Re: Order of destruct of local variables
Thomas Lehmann <t.lehm  2008-07-21 15:17:43 
Re: Order of destruct of local variables
ThosRTanner <ttanner2@  2008-07-21 15:20:25 
Re: Order of destruct of local variables
Alberto Ganesh Barbati &l  2008-07-21 23:15:15 
Re: Order of destruct of local variables
Thomas Lehmann <t.lehm  2008-07-22 15:31:22 
Re: Order of destruct of local variables
Le Chaud Lapin <jaibud  2008-07-22 15:58:15 
Re: Order of destruct of local variables
Dan Barbus <dan.barbus  2008-07-23 02:36:39 
Re: Order of destruct of local variables
JoshuaMaurice@[EMAIL PROT  2008-07-23 19:36:23 
Re: Order of destruct of local variables
Le Chaud Lapin <jaibud  2008-07-23 23:50:27 
Re: Order of destruct of local variables
Alberto Ganesh Barbati &l  2008-07-24 05:15:34 
Re: Order of destruct of local variables
JoshuaMaurice@[EMAIL PROT  2008-07-24 16:10:28 
Re: Order of destruct of local variables
Bart van Ingen Schenau &l  2008-07-24 16:08:12 
Re: Order of destruct of local variables
JoshuaMaurice@[EMAIL PROT  2008-07-24 17:22:17 
Re: Order of destruct of local variables
Le Chaud Lapin <jaibud  2008-07-24 19:58:15 
Re: Order of destruct of local variables
Eugene Gershnik <gersh  2008-07-25 02:46:32 
Re: Order of destruct of local variables
Nominal Pro <majorscio  2008-07-25 02:43:42 
Re: Order of destruct of local variables
Alberto Ganesh Barbati &l  2008-07-25 12:04:42 
Re: Order of destruct of local variables
Francis Glassborow <fr  2008-07-25 12:06:43 
Re: Order of destruct of local variables
Alberto Ganesh Barbati &l  2008-07-25 12:05:15 
Re: Order of destruct of local variables
Le Chaud Lapin <jaibud  2008-07-25 18:20:01 
Re: Order of destruct of local variables
Bart van Ingen Schenau &l  2008-07-25 18:19:47 
Re: Order of destruct of local variables
Alex <aleskx@[EMAIL PR  2008-07-25 18:25:28 
Re: Order of destruct of local variables
Eugene Gershnik <gersh  2008-07-26 13:27:15 
Re: Order of destruct of local variables
JoshuaMaurice@[EMAIL PROT  2008-07-27 03:18:50 
Re: Order of destruct of local variables
David Abrahams <dave@[  2008-07-27 03:28:18 
Re: Order of destruct of local variables
brangdon@[EMAIL PROTECTED  2008-07-27 15:35:17 
Re: Order of destruct of local variables
Nominal Pro <majorscio  2008-07-27 15:23:49 
Re: Order of destruct of local variables
bjarne <bjarne@[EMAIL   2008-07-27 15:37:41 
Re: Order of destruct of local variables
Alex <aleskx@[EMAIL PR  2008-07-27 15:36:50 
Re: Order of destruct of local variables
brangdon@[EMAIL PROTECTED  2008-07-28 12:37:25 
Re: Order of destruct of local variables
JoshuaMaurice@[EMAIL PROT  2008-07-28 17:58:18 
Re: Order of destruct of local variables
brangdon@[EMAIL PROTECTED  2008-07-29 15:28:19 
Re: Order of destruct of local variables
Mathias Gaunard <loufo  2008-07-27 15:41:11 
Re: Order of destruct of local variables
Nominal Pro <majorscio  2008-07-27 21:50:34 
Re: Order of destruct of local variables
Eugene Gershnik <gersh  2008-07-28 02:32:26 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 8:39:00 CDT 2008.