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

  1. Path: sparky!uunet!van-bc!rsoft!agate!ames!elroy.jpl.nasa.gov!decwrl!deccrl!bloom-beacon!eru.mt.luth.se!lunic!sunic!ericom!falcon!jonas
  2. From: jonas@beppe.ericsson.se (Jonas Nygren)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: destruction of temporaries
  5. Message-ID: <1992Aug19.113554.5464@ericsson.se>
  6. Date: 19 Aug 92 11:35:54 GMT
  7. References: <TMB.92Aug19113657@arolla.idiap.ch>
  8. Sender: news@ericsson.se
  9. Reply-To: jonas@beppe.ericsson.se
  10. Organization: Ericsson Telecom AB
  11. Lines: 55
  12. Nntp-Posting-Host: falcon.ericsson.se
  13.  
  14. In article 92Aug19113657@arolla.idiap.ch, tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
  15. > In article <1992Aug18.205211.16789@Warren.MENTORG.COM> adk@Warren.MENTORG.COM (Ajay Kamdar) writes:
  16. >    So why would the ARM consider the example with a temporary sufficient
  17. >    reason to reject the "end of function" approach? To me it appears that
  18. >    the "end of function" approach for temporaries would not cause any more
  19. >    difficulties or program bugs than those that can already occur even without
  20. >    temporaries. So why not reconsider that approach?
  21. > I don't want my temporaries to hang around until the end of the
  22. > function. I often use large temporaries (megabytes), and I see no
  23. > reason why they should stick around any longer than I need them.
  24. > Temporaries should get destroyed as soon as their value has been used.
  25.  
  26. Yes used is the right word. I gave a small example in a previous posting where
  27.  
  28.     s2 = s1.sub(2,3);
  29.  
  30. is OK, but
  31.  
  32.     s2 = s1.sub(2,3).strip();
  33.  
  34. is not. Why should this use be disallowed??
  35.  
  36. > To make call-by-reference a little more convenient, there is a special
  37. > rule for binding references to temporaries, and I guess that's OK.
  38.  
  39. Why is this use OK, on what is your 'guessing' based??
  40.  
  41. > The properties of temporaries are no different (and no worse) than the
  42. > properties of automatic variables: pointers to them become invalid
  43. > when the object disappears.
  44.  
  45. This is obvious. What we are discussing are when temporaries should disappear.
  46.  
  47. > If you want to be able to implement anything more powerful, you need
  48. > (surprise!) garbage collection (as stated in the ARM, p. 268). In the
  49.  
  50. If you read the referenced pages closely there are many points of destruction
  51. which are discussed and each giving some more 'power'. The ultimate solution
  52. might be GC. But without GC in the language we could try to make the language
  53. more 'intuitive' by  defining a reasonable behaviour for temporaries.
  54.  
  55. > presence of GC, you would then actually have a choice of destroying
  56. > the temporary yourself (the current situation, safe if no pointers to
  57. > it have been handed out), or of not destroying it at the end of the
  58. > expression and letting the GC take care of it.
  59. >                     Thomas.
  60.  
  61.  
  62. /jonas
  63.