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

  1. Xref: sparky comp.lang.c++:12280 comp.std.c++:1078
  2. Path: sparky!uunet!sunquest!bill
  3. From: bill@sunquest.UUCP (Bill Raves)
  4. Newsgroups: comp.lang.c++,comp.std.c++
  5. Subject: destruction of temporaries
  6. Message-ID: <46140@sunquest.UUCP>
  7. Date: 12 Aug 92 23:31:55 GMT
  8. Followup-To: comp.lang.c++
  9. Organization: Sunquest Information Systems, Tucson
  10. Lines: 26
  11.  
  12. We have encountered some widely different behavior in compilers (e.g.
  13. DEC C++ and cfront) with respect to the destruction of unnamed temporaries
  14. in contexts where a pointer or reference to object data is returned.
  15. We realize that compiler implementors have been given latitude in this
  16. area (see $12.2 of the ARM) and that the ANSI C++ standards committee is
  17. discussing this issue. We also realize that the manifestations of this
  18. behavior may introduce subtle bugs in code. The question is "How can
  19. we prevent these problems from getting into production code?".
  20.  
  21. One suggestion is to promulgate stylistic guidelines which caution
  22. against troublesome usage. For example, Jim Adcock has suggested
  23. (<70784@microsoft.UUCP>) "NEVER rely on unnamed temporaries to do
  24. anything...", but this would seem to erode the expressiveness of the
  25. language: constructs like "foo(x + y)" and "foo()[i]" would no longer
  26. be permissible. Henricson & Nyquist suggest "Do not write code which is
  27. dependent on the lifetime of a temporary object" but this seems too
  28. vague, especially for novice programmers, and seems to require us to
  29. know the details of the implementation.  What *specific* guidelines
  30. would you suggest for avoiding potential problems with unnamed tem-
  31. poraries?
  32.  
  33.  
  34. -- 
  35. Bill Raves                bill@sunquest.com
  36. Sunquest Information Systems        sunquest!bill@arizona.edu
  37. Tucson, AZ                              {arizona,uunet}!sunquest!bill
  38.