home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: destruction of temporaries
- Message-ID: <1992Aug21.005722.16573@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <1992Aug17.211508.6634@lucid.com> <1992Aug18.205211.16789@Warren.MENTORG.COM> <TMB.92Aug19113657@arolla.idiap.ch>
- Date: Fri, 21 Aug 1992 00:57:22 GMT
- Lines: 59
-
- In article <TMB.92Aug19113657@arolla.idiap.ch> tmb@idiap.ch writes:
- >In article <1992Aug18.205211.16789@Warren.MENTORG.COM> adk@Warren.MENTORG.COM (Ajay Kamdar) writes:
- >
- > So why would the ARM consider the example with a temporary sufficient
- > reason to reject the "end of function" approach? To me it appears that
- > the "end of function" approach for temporaries would not cause any more
- > difficulties or program bugs than those that can already occur even without
- > temporaries. So why not reconsider that approach?
- >
- >I don't want my temporaries to hang around until the end of the
- >function. I often use large temporaries (megabytes), and I see no
- >reason why they should stick around any longer than I need them.
- >
- >Temporaries should get destroyed as soon as their value has been used.
-
- As ordinary rvalues, a value can only get used ONCE.
- But as lvalues that isnt so:
-
- int i;
- (i=3)=4;
-
- Here i gets assigned to twice. For ordinary objects this is always
- meaningless, but for class based objects the assignment
- could have arbitrary side effects. So I'm not so sure when
- the 'value' has been used---it is not the value but the object
- that is being accessed twice.
-
- s(i,j)="Hello";
-
- Here the string s has operator()(int,int) applied to make a
- substring object to which an assignment is subsequently done,
- and that assignment copies the string "Hello" into the string
- s. S itself could sensibly be an expression ...
-
- print( (s1+s2)(i,j)="Hello" );
-
- so now how long does (s1+s2) have to last? Or is the above
- idiom bad news?
-
- >
- >The properties of temporaries are no different (and no worse) than the
- >properties of automatic variables: pointers to them become invalid
- >when the object disappears.
-
- When is that?
- >
- >If you want to be able to implement anything more powerful, you need
- >(surprise!) garbage collection (as stated in the ARM, p. 268).
-
- In other words, if you cant define a sensible
- length of time for temporaries to hang around on a static basis,
- then dont--define it dynamically.
-
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-