home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12871 < prev    next >
Encoding:
Internet Message Format  |  1992-08-25  |  2.1 KB

  1. 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
  2. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Proposal: auto T&
  5. Message-ID: <TMB.92Aug25221145@arolla.idiap.ch>
  6. Date: 26 Aug 92 02:11:45 GMT
  7. References: <1992Aug19.234913.622@tfs.com> <2A991ABB.477D@tct.com>
  8.     <9223817.24813@mulga.cs.mu.OZ.AU> <17dlcaINNafv@early-bird.think.com>
  9. Sender: news@ai.mit.edu
  10. Reply-To: tmb@idiap.ch
  11. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  12.     Perceptive)
  13. Lines: 28
  14. In-reply-to: barmar@think.com's message of 25 Aug 92 15:59:06 GMT
  15.  
  16. In article <17dlcaINNafv@early-bird.think.com> barmar@think.com (Barry Margolin) writes:
  17.  
  18.    In article <9223817.24813@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  19.    >Here again compilers should be smart enough to optimize away the both the
  20.    >unnamed temporary AND the named temporary "retval".
  21.    >I don't know whether the latter optimization is allowed by the ARM
  22.    >(I suspect not), but it SHOULD be.
  23.  
  24.    It is in limited cases.  Sec. 3.5 of the ARM explicitly says, "nor may an
  25.    automatic named object of a class with a constructor or a destructor with
  26.    side effects be eliminated even if it appears to be unused."  In most
  27.    cases, I suspect compilers won't check for the "with side effects" (if the
  28.    constructor or destructor isn't inline, they generally can't), and some
  29.    compilers may not even check whether the class has a contructor or
  30.    destructor.
  31.  
  32. Yes, and this rule is unlikely to change. People are using
  33. constructors/destructors not only for memory management but also as a
  34. form of UNWIND-PROTECT (e.g., create a window on block entry and make
  35. sure it gets destroyed on block exit, no matter what).
  36.  
  37. I think this is in line with the C/C++ philosophy of using a "small"
  38. number of primitives for as many purposes as possible. In C++, classes
  39. are being used for OO programming, as modules, and for cleanup jobs at
  40. the end of blocks. I'm not sure whether this is a good strategy in the
  41. long run.
  42.  
  43.                     Thomas.
  44.