home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / std / cplus / 2107 < prev    next >
Encoding:
Text File  |  1993-01-23  |  4.1 KB  |  83 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!slsvaat!us-es.sel.de!reindorf
  3. From: reindorf@us-es.sel.de (Charles Reindorf)
  4. Subject: Re: Compiler should generate virtual destructors
  5. Message-ID: <1993Jan23.081616.29910@us-es.sel.de>
  6. Sender: news@us-es.sel.de
  7. Organization: SEL-Alcatel Line Transmission Systems Dept. US/ES
  8. References: <1992Dec31.050150.28929@ucc.su.OZ.AU> <lkc2k7INNajv@exodus.Eng.Sun.COM> <harvey.727664973@regina> <24679@alice.att.com>
  9. Date: Sat, 23 Jan 93 08:16:16 GMT
  10. Lines: 71
  11.  
  12. In article <lm0gudINN9be@exodus.Eng.Sun.COM>, chased@rbbb.Eng.Sun.COM (David Chase) writes:
  13. |> In article <1993Jan22.081555.12027@us-es.sel.de> reindorf@us-es.sel.de (Charles Reindorf) writes:
  14. |> >On the subject of "trampolenes" in the implementation of nested functions, this 
  15. |> >presumably means the following appraoch:
  16. |> 
  17. |> > [code generation into stack frame, which works.]
  18. |> > ... The main objection I can see is that on some operating systems
  19. |> >you are not allowed to do any run-time code generation.
  20. |> 
  21. |> One workaround is to keep a cache of trampolines, which in this case
  22. |> are pairs of code+data, where each piece of code is compiled to
  23. |> reference a particular piece of data.  Some run-time code generation
  24. |> must still occur.  In the limit case (the least flexible OSes) a
  25. |> different calling convention must be used for all function calls.
  26.  
  27. As you say, the cache appraoch still involves generating code on the fly, 
  28. or making the function pointer data type more complex (impacting all cases) 
  29. and changing the procedure call convention.
  30. |> 
  31. |> >Other people talk about "bound" functions which presumably means that
  32. |> >given an object a of class A with member function f, then "a.f" can be
  33. |> >regarded as a new function (whose pointer can be taken) with a non
  34. |> >member-function signature.  The only way I can see of using a
  35. |> >trampolene appraoch for this situation is to place the trampolene for
  36. |> >the function a.f into the object a itself.
  37. |> 
  38. |> Actually, you could "new" them.  Just allocate the functions on the
  39. |> "heap", and free them when you are done.  Or, we could take a flying
  40. |> leap at the slippery slope and add garbage collection.
  41.  
  42. Again, as you say, you have to free them "when you are done", but in 
  43. this situation, there is no natural idea of "when you are done". In 
  44. fact, whereas the natural lifetime of a nested function is until the 
  45. containing function completes, the natural lifetime of a bound function 
  46. is until the destruction of the object to which it is bound. How do you 
  47. ensure that whenever an object dies, that bound function trampolenes 
  48. which *might* have been generated for it are deleted? (Bearing in mind 
  49. that the object may not otherwise need any destructor and may not have 
  50. any virtual functions at all).
  51.  
  52. |> >This surely makes member function closures an impracticable and
  53. |> >unworkable addition to the language?
  54. |> 
  55. |> I think the answer is another question: "compared to what?"  I'm
  56. |> really looking forward to run-time instantiation of templates.
  57.  
  58. I can see no way that the solution can be implemented in a way that 
  59. doen't impact the normal performance of the system. The only way I 
  60. can see round this is to add something to the syntax of the language 
  61. to indicate "this member function might be bound" at the point of 
  62. declaration. To me, this is unacceptable.
  63.  
  64. None of this detracts from the fact that *nested* functions *can* be 
  65. implemented without impacting on the normal performance of the system, 
  66. and without requiring any special new constructs in the language (more 
  67. a relaxation of a rule). What's more, they are extremely valid for 
  68. situations where iterators are used for many general call-back 
  69. mechanisms which are considerably more awkward (or unsafe) when done 
  70. using one of the manual alternatives.
  71.  
  72. Moreover, if nested functions are implemented, they imply an easy 
  73. manual solution to many cases where bound member functions might have 
  74. been required. Other cases where bound member functions might be 
  75. required can surely be solved through abstract base classes and in some 
  76. cases MI.
  77.  
  78. |> 
  79. |> David Chase
  80. |> Sun
  81.  
  82.  
  83.