home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12464 < prev    next >
Encoding:
Text File  |  1992-08-17  |  1.8 KB  |  40 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!microsoft!hexnut!jimad
  3. From: jimad@microsoft.com (Jim Adcock)
  4. Subject: Re: destruction of temporaries
  5. Message-ID: <1992Aug17.233923.14077@microsoft.com>
  6. Date: 17 Aug 92 23:39:23 GMT
  7. Organization: Microsoft Corporation
  8. References: <46140@sunquest.UUCP>
  9. Lines: 29
  10.  
  11. In article <46140@sunquest.UUCP> bill@sunquest.UUCP (Bill Raves) writes:
  12. |For example, Jim Adcock has suggested
  13. |(<70784@microsoft.UUCP>) "NEVER rely on unnamed temporaries to do
  14. |anything...", but this would seem to erode the expressiveness of the
  15. |language: constructs like "foo(x + y)" and "foo()[i]" would no longer
  16. |be permissible. 
  17.  
  18. When an unnamed temporary is assigned to a reference, then the unnamed
  19. temporary is no longer unnamed.  I believe this should mean that the lifetime
  20. of the temporary then becomes that of the reference, but its easy to find
  21. lots of compilers that disagree with this.
  22.  
  23. The bottom line is, if you DO rely on unnamed temporaries to do anything,
  24. you WILL be disappointed in the code generated by one or more compilers.
  25.  
  26. Some years after the ansi committee decides on the life times of temporaries,
  27. what it means to give a name to a previously unnamed temporary [by assigning
  28. it to a reference] whether functions return by copy or by value, when compilers
  29. can create temporaries, and when compilers can leave them out, and how many
  30. of these temporaries are created or not, what sequences points are and where
  31. they exist, what "const" means, and what "volatile" means....
  32.  
  33. .... when the committee decides on these things, if ever, and then some
  34. years later when C++ compiler reliably implement the standard, THEN and only
  35. then can you, in practice, rely on the behavior of temporaries.  UNTIL THEN, 
  36. good luck.
  37.  
  38. Today, if you want to write portable code, rely on named temporaries.
  39.  
  40.