home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:15996 comp.std.c++:1523
- Path: sparky!uunet!sun-barr!decwrl!spool.mu.edu!darwin.sura.net!tulane!uflorida!travis.csd.harris.com!amber!bill
- From: bill@amber.csd.harris.com (Bill Leonard)
- Newsgroups: comp.lang.c++,comp.std.c++
- Subject: Re: PROPOSAL: Hidden private parts of classes
- Message-ID: <1dmed7INNk5f@travis.csd.harris.com>
- Date: 9 Nov 92 19:32:55 GMT
- 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>
- Distribution: ssd
- Organization: Harris CSD, Ft. Lauderdale, FL
- Lines: 52
- NNTP-Posting-Host: amber.ssd.csd.harris.com
-
- In article <klamer.721303355@mi.el.utwente.nl>, klamer@mi.el.utwente.nl (Klamer Schutte) writes:
- >
- > I doubt it. I can't see how a compiler can build a stack frame with
- > auto variables, if the sizes of the elements on the stack frame are
- > unknown. What can be done, is putting a pointer to the actual data in
- > the stack frame, and allocate the data element itself on some heap
- > (preferably a fast one, like alloca()).
- >
- > Otherwise the offsets of individual elements in the stack frame are unknown
- > at compile time. These might be patched back at link time. (seems dirty
- > to me). Allowing this you might loose some optimization opportunities.
-
- Why do stack frames have to be fixed size? Many languages, including Ada,
- allow for automatic objects whose size is determined at runtime. This is
- not new technology, nor even all that hard. In most implementations, the
- compiler allocates a fixed-size part of the frame for its own use (like
- register saving and such), plus all the known-sized automatic objects. It
- then computes the amount of space needed for variable-sized objects and
- extends the stack frame by that amount.
-
- In some languages, like Ada for instance, variable-sized objects can even
- be declared in nested blocks and/or returned from functions! This means
- that the stack frame must grow and shrink as the function executes. That
- gets a little more complicated, but again, the technology is not new.
-
- I think the clever thing to do for C++ would be to make the sizeof operator
- be specifiable by the user, with arguments specified after the constructor
- arguments, say. For instance:
-
- Foo * x = new Foo(/* constructor args */) (/* sizeof args */) ;
-
- The built-in sizeof operator would automatically generate a function if the
- size of the object is not known at compile-time. This would necessitate,
- of course, some way to indicate that you wanted to defer the complete
- specification of the class in its declaration, and also some way to
- complete that specification elsewhere.
-
- As much as I would like to see this feature, though, I wouldn't argue for
- its inclusion in the current standard. Defer it until the next revision,
- perhaps. The standard has dragged on long enough -- it certainly has
- enough in it to be useful (as evidenced by the large number of C++ users
- already).
-
- --
- Bill Leonard
- Harris Computer Systems Division
- 2101 W. Cypress Creek Road
- Fort Lauderdale, FL 33309
- bill@ssd.csd.harris.com
- ---------------------------------------------------------------------------
- Prism: A place for light waves that commit minor refractions.
- ---------------------------------------------------------------------------
-