Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!wuarchive!uunet!lupine!rfg From: rfg@NCD.COM (Ron Guilmette) Newsgroups: comp.std.c++ Subject: Re: "packed" objects Message-ID: <1030@lupine.NCD.COM> Date: 31 Jul 90 22:52:38 GMT References: <56159@microsoft.UUCP> <56165@microsoft.UUCP> Organization: Network Computing Devices, Inc., Mt. View, CA Lines: 64 In article <56165@microsoft.UUCP> jimad@microsoft.UUCP (Jim ADCOCK) writes: >Proposed: > >We need a way to "pack" objects over inheritence boundaries, and possibly >between labeled fields of a declaration. I do not propose here exactly >what the "right" way to do this is. > >I claim this is important because I see lots of examples of serious C++ >programmers implementing "hacks" to "pack" objects across inheritence >boundaries. Examples include: Base class B needs two bits, and derived >class D needs three bits, so let's implement a bit sharing hack between >base and derived... It's an obvious and serious problem. Yes. >... Features commonly used should be >part of the language, not implemented via "hack" word-arounds. Quite so. >Possible full or partial "solutions" to this problem include: > >* Throw out the current C++ restrictions on field ordering entirely. What >does it buy us anyway? If you mean the rule that says that all protected members get clumped together (despite my best efforts and intentions, and no matter what I would prefer) then yes. This restrictive and irritating rule should be thrown out. What ever happened to the philosophy that says that the programmer knows what he want's, so (unless it obviously stupid *and* dangerous) let him do what he wants? >Use 'extern "C"' where an object needs backwards >compatibility to "C" packing order. Huh? >* Require current field ordering restrictions be maintained on things declared >"struct", but removed restrictions on anything declared "class." Bad idea. >* Introduce an explicit keyword "packed" or similar. Declaring a base class >"packed" turns off field ordering restrictions in that class and its >derivatives, as well as representing a directive to the compiler that small >size is to be preferred to fast access. Possibly vtable ptrs could also >be replaced with smaller type tags in such classes.... Since the issue involves the boundary between a derived class and exactly one of its base classes, I suggest that perhaps "packed" should be a way of doing inheritance, e.g.: class doe : public rea, packed public me { ... }; would specify that the earliest field of `doe' should get packed up against the latest field of `me'. -- // Ron Guilmette // C++ Entomologist // Internet: rfg@ncd.com uucp: ...uunet!lupine!rfg // Motto: If it sticks, force it. If it breaks, it needed replacing anyway.