home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!jvnc.net!yale.edu!yale!gumby!destroyer!sol.ctr.columbia.edu!eff!snorkelwacker.mit.edu!ai-lab!life.ai.mit.edu!tmb
- From: tmb@arolla.idiap.ch (Thomas M. Breuel)
- Newsgroups: comp.lang.c++
- Subject: Re: Proposal: auto T&
- Message-ID: <TMB.92Aug25221145@arolla.idiap.ch>
- Date: 26 Aug 92 02:11:45 GMT
- References: <1992Aug19.234913.622@tfs.com> <2A991ABB.477D@tct.com>
- <9223817.24813@mulga.cs.mu.OZ.AU> <17dlcaINNafv@early-bird.think.com>
- Sender: news@ai.mit.edu
- Reply-To: tmb@idiap.ch
- Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
- Perceptive)
- Lines: 28
- In-reply-to: barmar@think.com's message of 25 Aug 92 15:59:06 GMT
-
- In article <17dlcaINNafv@early-bird.think.com> barmar@think.com (Barry Margolin) writes:
-
- In article <9223817.24813@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
- >Here again compilers should be smart enough to optimize away the both the
- >unnamed temporary AND the named temporary "retval".
- >I don't know whether the latter optimization is allowed by the ARM
- >(I suspect not), but it SHOULD be.
-
- It is in limited cases. Sec. 3.5 of the ARM explicitly says, "nor may an
- automatic named object of a class with a constructor or a destructor with
- side effects be eliminated even if it appears to be unused." In most
- cases, I suspect compilers won't check for the "with side effects" (if the
- constructor or destructor isn't inline, they generally can't), and some
- compilers may not even check whether the class has a contructor or
- destructor.
-
- Yes, and this rule is unlikely to change. People are using
- constructors/destructors not only for memory management but also as a
- form of UNWIND-PROTECT (e.g., create a window on block entry and make
- sure it gets destroyed on block exit, no matter what).
-
- I think this is in line with the C/C++ philosophy of using a "small"
- number of primitives for as many purposes as possible. In C++, classes
- are being used for OO programming, as modules, and for cleanup jobs at
- the end of blocks. I'm not sure whether this is a good strategy in the
- long run.
-
- Thomas.
-