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

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!masscomp!peora!tarpit!fang!att!allegra!alice!ark
  2. From: ark@alice.att.com (Andrew Koenig)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: destruction of temporaries
  5. Message-ID: <23466@alice.att.com>
  6. Date: 17 Aug 92 12:24:36 GMT
  7. Article-I.D.: alice.23466
  8. References: <BszApE.49v@world.std.com> <1992Aug17.073500.24115@ericsson.se>
  9. Reply-To: ark@alice.UUCP ()
  10. Organization: AT&T Bell Laboratories, Liberty Corner NJ
  11. Lines: 38
  12.  
  13. In article <1992Aug17.073500.24115@ericsson.se> jonas@beppe.ericsson.se writes:
  14.  
  15. > IMO temporaries should survive until end of statement.
  16.  
  17. This treatment has two significant disadvantages:
  18.  
  19.     1. If I break a statement up into several, it may
  20.        quietly change its meaning.  Thus, for example, if
  21.        String::operator const char*() exists, and s and t are
  22.        of class String, then
  23.  
  24.         printf("%s\n", (const char*)(s+t));
  25.     
  26.        might work but
  27.  
  28.         const char* r = s + t;
  29.         printf("%s\n", r);
  30.        
  31.        might not.
  32.  
  33.     2. It is a real pain to implement for statements that
  34.        generate temporaries inside conditionals.  Thus, for
  35.        example, in x>0?f(p+q):r, if p+q generates a temporary,
  36.        and it was necessary to wait until the end of the statement
  37.        to destroy it, it would also be necessary to remember which
  38.        branch of the ?: was taken to decide whether or not to
  39.        destroy it.  There are cases where this can add substantially
  40.        to execution time.  Moreover, it greately complicates the
  41.        implementation of exception handling, because it makes it
  42.        impossible to have a static map from program counter value
  43.        to offsets of statics to destroy.
  44.  
  45. For these reasons, I think a shorter lifetime than end of statement
  46. is appropriate for temporaries.  Whether the committee will go that
  47. way, however, remains to be seen.
  48. -- 
  49.                 --Andrew Koenig
  50.                   ark@europa.att.com
  51.