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

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!enterpoop.mit.edu!ira.uka.de!slsvaat!us-es.sel.de!reindorf
  3. From: reindorf@us-es.sel.de (Charles Reindorf)
  4. Subject: Re: Use of nested functions
  5. Message-ID: <1993Jan27.094029.5737@us-es.sel.de>
  6. Sender: news@us-es.sel.de
  7. Organization: SEL-Alcatel Line Transmission Systems Dept. US/ES
  8. References: <1993Jan13.174051.21288@ucc.su.OZ.AU> <9302002.3172@mulga.cs.mu.OZ.AU> <1993Jan22.081555.12027@us-es.sel.de> <1993Jan26.224107.9187@ucc.su.OZ.AU>
  9. Date: Wed, 27 Jan 93 09:40:29 GMT
  10. Lines: 77
  11.  
  12. In article <1993Jan26.224107.9187@ucc.su.OZ.AU>, maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) 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, 
  15. |> >this >presumably means the following appraoch:
  16. |> >
  17. |> >Some people say that they "don't like" trampolenes, but don't seem to give any
  18. |> >reason for it. 
  19. |> 
  20. |>     Separation of code and data is an important machine
  21. |> principle for safety. Some machines (all the good ones :-) do not
  22. |> allow executing things in the data area.
  23. |> 
  24. |>     Trampolines feel a bit like the Cobol ALTER statement:
  25. |> dangerous hacks.
  26. |> 
  27. |> >The main objection I can see is that on some operating systems
  28. |> >you are not allowed to do any run-time code generation. 
  29. |> 
  30. |>     Some OS may not grant the user the priviledges required
  31. |> to generate and execute code on the fly. This is because
  32. |> it is close to 'self-modifying' code, which is not
  33. |> generally considerd very safe.
  34. |> 
  35. |> >But there again, in 
  36. |> >these architectures there do exist other, 
  37. |> >addmittedly less efficient workarounds
  38. |> >to this problem, surely.
  39. |> 
  40. |>     Such as? I would LOVE to hear of one that did not require
  41. |> the standard C/C++ function pointers to double in size.
  42.  
  43. The whole issue is surely a matter dealt with heavily by PASCAL implementations. I suspect
  44. that some implementations (e.g. MS-DOS ones) use trampolenes whereas others use double-size
  45. function pointers. The question is, are C++ implementors ready to tackle the matter. My
  46. feeling is that it adds a great deal of extra power to the language in return for the
  47. penalty. However, I also understand that there is already a greaty deal on the plate for 
  48. the C++ standardisation committee. That's my 2 cents worth.
  49.  
  50. |> 
  51. |> >
  52. |> >Other people talk about "bound" functions which presumably means that given an
  53. |> >object a of class A with member function f, then "a.f" can be regarded as a new
  54. |> >function (whose pointer can be taken) with a non member-function signature. The 
  55. |> >only way I can see of using a trampolene appraoch for this situation is to place
  56. |> >the trampolene for the function a.f into the object a itself. This increases
  57. |> >the memory overhead for function a. In fact, the compiler would have to do
  58. |> >this by default for every member function of a, because it won't know in
  59. |> >advance which will be bound (without ghastly extensions to the language). This
  60. |> >surely makes member function closures an impracticable and unworkable addition
  61. |> >to the language?
  62. |> >
  63. |> 
  64. |>     No, one can just leave it up to the user to delete the
  65. |> trampoline---as for other dynamically allocated objects. It is not
  66. |> as 'safe' as puting the trampoline in the object (or a pointer thereto),
  67. |> but even that isnt safe (the trampoline could still be called
  68. |> after it was deleted --- very nasty crash following, perhaps sometime
  69. |> later).
  70.  
  71. This idea sounds very messy to me (to say the least). Can you describe the mechanism
  72. for this in the language? My contention here would be : it's really not worth the
  73. trouble. This sort of problem can be solved in other ways: If you have nested functions,
  74. they can sometimes be used to forward the callback and otherwise you are likely best off
  75. using a pointer to an abstract base class in preference to a pointer to a bound function.
  76. There may be examples around where neither of these two approaches are suitable. Does 
  77. anybody know of any?
  78.  
  79. |> 
  80. |> 
  81. |> -- 
  82. |> ;----------------------------------------------------------------------
  83. |>         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  84. |>     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  85. |> ;------ SCIENTIFIC AND ENGINEERING SOFTWARE ---ph:  2 799 8223 --------
  86.  
  87.  
  88. --- Charles Reindorf
  89.