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

  1. Path: sparky!uunet!cs.utexas.edu!usc!rpi!uwm.edu!linac!att!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: <23585@alice.att.com>
  6. Date: 29 Aug 92 13:10:17 GMT
  7. Article-I.D.: alice.23585
  8. References: <23487@alice.att.com> <MATT.92Aug19170229@physics16.berkeley.edu> <1992Aug25.175751.8117@microsoft.com> <1992Aug28.221841.149034@Cookie.secapl.com>
  9. Reply-To: ark@alice.UUCP ()
  10. Organization: AT&T Bell Laboratories, Murray Hill NJ
  11. Lines: 21
  12.  
  13. In article <1992Aug28.221841.149034@Cookie.secapl.com> frank@Cookie.secapl.com (Frank Adams) writes:
  14.  
  15. > I don't claim to have a complete solution to the problem.  However, for the
  16. > specific case   c ? a+b : a   where a+b creates a temporary, I would be
  17. > tempted (as a compiler writer) to always return a temporary: a+b if c is
  18. > true, and a copy of a otherwise.  This solves the problem of not knowing
  19. > whether a temporary has been created.
  20.  
  21. I'm afraid it doesn't solve the problem.  For example, suppose `a' is of type
  22. const char*, `b' is of type String, and String has one of those problematic
  23. conversions to const char*.  Now, let's modify your example a tiny bit and
  24. look at c?(const char*)(a+b):a.
  25.  
  26. This expression always returns a value of type const char*, but that's not
  27. where the problem likes: the problem is in the temporary of type String
  28. yielded by the subexpression a+b.  The value of (const char*)(a+b) is valid
  29. only so long as that temporary stays around, so any games you play with
  30. the const char* values themselves won't affect that.
  31. -- 
  32.                 --Andrew Koenig
  33.                   ark@europa.att.com
  34.