home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 15996 < prev    next >
Encoding:
Internet Message Format  |  1992-11-09  |  3.3 KB

  1. Xref: sparky comp.lang.c++:15996 comp.std.c++:1523
  2. Path: sparky!uunet!sun-barr!decwrl!spool.mu.edu!darwin.sura.net!tulane!uflorida!travis.csd.harris.com!amber!bill
  3. From: bill@amber.csd.harris.com (Bill Leonard)
  4. Newsgroups: comp.lang.c++,comp.std.c++
  5. Subject: Re: PROPOSAL: Hidden private parts of classes
  6. Message-ID: <1dmed7INNk5f@travis.csd.harris.com>
  7. Date: 9 Nov 92 19:32:55 GMT
  8. References: <1992Oct30.113234.15010@daimi.aau.dk> <1csnjaINNqa0@hpsdlss3.sdd.hp.com> <klamer.720538594@mi.el.utwente.nl> <1992Nov7.155248.23401@ucc.su.OZ.AU> <klamer.721303355@mi.el.utwente.nl>
  9. Distribution: ssd
  10. Organization: Harris CSD, Ft. Lauderdale, FL
  11. Lines: 52
  12. NNTP-Posting-Host: amber.ssd.csd.harris.com
  13.  
  14. In article <klamer.721303355@mi.el.utwente.nl>, klamer@mi.el.utwente.nl (Klamer Schutte) writes:
  15. > I doubt it. I can't see how a compiler can build a stack frame with
  16. > auto variables, if the sizes of the elements on the stack frame are
  17. > unknown. What can be done, is putting a pointer to the actual data in
  18. > the stack frame, and allocate the data element itself on some heap
  19. > (preferably a fast one, like alloca()). 
  20. > Otherwise the offsets of individual elements in the stack frame are unknown
  21. > at compile time. These might be patched back at link time. (seems dirty
  22. > to me). Allowing this you might loose some optimization opportunities.
  23.  
  24. Why do stack frames have to be fixed size?  Many languages, including Ada,
  25. allow for automatic objects whose size is determined at runtime.  This is
  26. not new technology, nor even all that hard.  In most implementations, the
  27. compiler allocates a fixed-size part of the frame for its own use (like
  28. register saving and such), plus all the known-sized automatic objects.  It
  29. then computes the amount of space needed for variable-sized objects and
  30. extends the stack frame by that amount.
  31.  
  32. In some languages, like Ada for instance, variable-sized objects can even
  33. be declared in nested blocks and/or returned from functions!  This means
  34. that the stack frame must grow and shrink as the function executes.  That
  35. gets a little more complicated, but again, the technology is not new.
  36.  
  37. I think the clever thing to do for C++ would be to make the sizeof operator
  38. be specifiable by the user, with arguments specified after the constructor
  39. arguments, say.  For instance:
  40.  
  41.     Foo   * x = new Foo(/* constructor args */) (/* sizeof args */) ;
  42.  
  43. The built-in sizeof operator would automatically generate a function if the
  44. size of the object is not known at compile-time.  This would necessitate,
  45. of course, some way to indicate that you wanted to defer the complete
  46. specification of the class in its declaration, and also some way to
  47. complete that specification elsewhere.
  48.  
  49. As much as I would like to see this feature, though, I wouldn't argue for
  50. its inclusion in the current standard.  Defer it until the next revision,
  51. perhaps.  The standard has dragged on long enough -- it certainly has
  52. enough in it to be useful (as evidenced by the large number of C++ users
  53. already).
  54.  
  55. -- 
  56. Bill Leonard
  57. Harris Computer Systems Division
  58. 2101 W. Cypress Creek Road
  59. Fort Lauderdale, FL  33309
  60. bill@ssd.csd.harris.com
  61. ---------------------------------------------------------------------------
  62. Prism: A place for light waves that commit minor refractions.
  63. ---------------------------------------------------------------------------
  64.