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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: destruction of temporaries
  5. Message-ID: <1992Aug21.010755.17454@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1992Aug18.205211.16789@Warren.MENTORG.COM> <TMB.92Aug19113657@arolla.idiap.ch> <1992Aug19.111836.25070@lth.se>
  10. Date: Fri, 21 Aug 1992 01:07:55 GMT
  11. Lines: 54
  12.  
  13. In article <1992Aug19.111836.25070@lth.se> dag@control.lth.se (Dag Bruck) writes:
  14. >In <comp.lang.c++> tmb@idiap.ch writes:
  15. >>The properties of temporaries are no different (and no worse) than the
  16. >>properties of automatic variables: pointers to them become invalid
  17. >>when the object disappears.
  18. >
  19. >I think there is a major difference.  The programmer controls the
  20. >scope of automatic variables and hence their lifetime.  Temporaries
  21. >are created by the compiler (possibly because of ill-advised
  22. >programming techniques) and the programmer has no control over their
  23. >lifetime.
  24. >
  25. >The language does not specify under what circumstances temporaries are
  26. >created, and I'm willing to accept that, but it should at least
  27. >specify their lifetime in expressions that potentially create
  28. >temporaries.
  29. >
  30. >Given the deliberations for and against different models [no details
  31. >given] I would probably prefer destruction at greatest enclosing
  32. >expression, 
  33.  
  34.     Do you mean the next semicolon? I think thats what
  35. you just said isn't it?
  36.  
  37. >with the additional constraint that temporaries created in
  38. >one "arm" of a conditional expression are destroyed at the end of that
  39. >conditional expression.
  40.  
  41.     As a matter of interest, what is the status of
  42.  
  43.     (a<b ? a : b )=1;
  44.  
  45. If a and b were just integers, they would need to be construed as
  46. lvalues for the above to make any sense. But that is not
  47. true for classes where the concept of lvalue is not so well
  48. defined. It is possible if not sensible to assign a value
  49. to a temporary class object and obtains a persistent
  50. result through side effects. Because assignment has no
  51. special status for class objects.
  52. >
  53. >With respect to difficulty of implementation, in particular combined
  54. >with exception handling, it would probably pay off to look at existing
  55. >implementations (I can think of HP and IBM) before making any judgements.
  56.  
  57.     Desstroying temporaries at the right time seems not so hard.
  58. Defining the right time is harder (if not impossible without GC).
  59. And making exceptions work is harder still (since RTTI is required
  60. in their present form)
  61.  
  62. -- 
  63. ;----------------------------------------------------------------------
  64.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  65.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  66. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  67.