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

  1. Path: sparky!uunet!kithrup!hoptoad!decwrl!deccrl!bloom-beacon!eru.mt.luth.se!lunic!sunic!mcsun!Germany.EU.net!unido!starlab!mi
  2. From: mi@starlab.UUCP (Michael Hoennig)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: destruction of temporaries
  5. Keywords: temporaries,destruction,statements,block,early
  6. Message-ID: <3920@starlab.UUCP>
  7. Date: 19 Aug 92 06:36:38 GMT
  8. References: <BszApE.49v@world.std.com> <1992Aug17.073500.24115@ericsson.se> <23466@alice.att.com>
  9. Organization: StarDivision GmbH, D-2000 Hamburg, Germany
  10. Lines: 50
  11.  
  12. In article <23466@alice.att.com> ark@alice.UUCP () writes:
  13. >
  14. >    1. If I break a statement up into several, it may
  15. >       quietly change its meaning.  Thus, for example, if
  16. >       String::operator const char*() exists, and s and t are
  17. >       of class String, then
  18. >
  19. >        printf("%s\n", (const char*)(s+t));
  20. >    
  21. >       might work but
  22. >
  23. >        const char* r = s + t;
  24. >        printf("%s\n", r);
  25. >       
  26. >       might not.
  27. In my opinion the result shouldn't be to destroy temporaries such early - 
  28. and of cause not more early (before the end of the statement). 
  29.  
  30. >For these reasons, I think a shorter lifetime than end of statement
  31. >is appropriate for temporaries.  Whether the committee will go that
  32. >way, however, remains to be seen.
  33.  
  34. Why shorter, Andrew? Why not like all other automatic instances (those
  35. on the stack) at the end of the block? In this case everyone can exactly
  36. recocnize when the temporaries will be destroyes - and of cause too you
  37. can exactly determine the point of destruction, simply be creating 
  38. additional blocks. As shown here:
  39.  
  40. int foo()
  41. {
  42.     Class a1, a2;
  43.     { cout << a1+a2; }    // immediately after using - destroy
  44.     ... /// do more stuff - without the temporary
  45. }
  46.  
  47. I think - the earlier temporaries will be destroyed, the more silent bugs
  48. will be in C++ programs. Of cause we can't destroy them too late, but there
  49. must be coosen a safe and determinable rule.
  50.  
  51. Please, dont't destroy them immediatley. Many elegant constructions
  52. in C++ programs (as shown in examples in this news thread) won't be
  53. possible anymore.
  54.  
  55. Adios
  56.  
  57. -- 
  58. Michael Hoennig                                  FAX:   +49 40 23 646 550
  59. StarDivision GmbH                                Phone: +49 40 23 646 500
  60. Sachsenfeld 4                                    uucp: ...!unido!starlab!mi
  61. D-W-2000 Hamburg 1                               domain: mi@starlab.uucp
  62.