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

  1. Path: sparky!uunet!mcsun!corton!seti!goudurix.inria.fr!edelson
  2. From: daniel.edelson@inria.fr (Daniel R. Edelson)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: destruction of temporaries
  5. Keywords: temporaries,destruction,statements,block,early
  6. Message-ID: <4091@seti.UUCP>
  7. Date: 20 Aug 92 11:35:22 GMT
  8. References: <BszApE.49v@world.std.com> <1992Aug17.073500.24115@ericsson.se> <23466@alice.att.com> <3920@starlab.UUCP> <23487@alice.att.com>
  9. Sender: news@seti.UUCP
  10. Reply-To: Daniel R. Edelson <daniel.edelson@inria.fr>
  11. Organization: INRIA -- Institut National de Recherche en Informatique et Automatique -- Rocquencourt, France
  12. Lines: 54
  13.  
  14.  
  15. I'm not an expert on this issue, and so will just make one
  16. quick point and then shut up.
  17.  
  18. In article <23487@alice.att.com>, ark@alice.att.com (Andrew Koenig) writes:
  19. |> In article <3920@starlab.UUCP> mi@starlab.UUCP (Michael Hoennig) writes:
  20. |> 
  21. |>     3. I have heard comments from users who really want temporaries
  22. |>        cleaned up early if possible.  Typically they are using linear
  23. |>        algrbra packages and write things like this:
  24. |> 
  25. |>         Matrix D = A * B * C;
  26. |>        
  27. |>        and do not want the intermediate result A * B to hang around
  28. |>        until the end of the block.  Of course they can't enclose this
  29. |>        in braces because then that would tear down D as well.  Moreover,
  30. |> 
  31. |>         Matrix D;
  32. |>         {
  33. |>             D = A * B * C;
  34. |>         }
  35. |> 
  36. |>        in addition to being ungainly, substitutes assignment for
  37. |>        initialization.  This can be significantly slower in some
  38. |>        implementations.
  39.  
  40. It seems as though there is a tension between early destruction and
  41. late destruction. The numerical scientists prefer early destruction 
  42. because their temporaries are very large and consume substantial
  43. resources. Some others advocate late destruction because that
  44. reduces the likelihood of dangling references.
  45.  
  46. My only observation is that correctness may be more important
  47. than efficiency. Though early destruction may make some programs
  48. run faster, will it introduce a disproportionate number of errors?
  49.  
  50. Also, what language will the Standard use to specify this. Assume
  51. that the Standard defines when temporaries are destroyed. My fear
  52. is that it will become 'undefined behavior' to hold a reference to
  53. a temporary beyond the point where the temporary may have been
  54. destroyed. Undefined behavior means that the programmer is wrong
  55. but the compiler need not say anything. Thus, this can lead to
  56. insiduous bugs that only appear under certain compilers, or
  57. perhaps only with optimization enabled, etc.
  58.  
  59. Mere Mortals (tm) should be able to understand why their C++
  60. program is or is not legal, without having to pester their
  61. local guru every 15 minutes. (You can tell that my prime 
  62. consideration is not job security.)
  63.  
  64. |>                 --Andrew Koenig
  65. |>                   ark@europa.att.com
  66.  
  67. Daniel.Edelson@inria.fr
  68.