From: Erik Corry <erik@arbat.com>
Subject: Fragile Base Class
Date: 1999/05/06 [thread overview]
Message-ID: <7gsbfp$25ej3$1@xinwen.daimi.au.dk> (raw)
In-Reply-To: 373197F3.BA3DC720@cs.city.ac.uk
In comp.arch Greg Law <gel@cs.city.ac.uk> wrote:
> Erik Corry wrote:
>>
>> In comp.arch Zalman Stern <zalman@netcom.com> wrote:
>>
>> > There is definitely room for improvement in binary interoperability in C++
>> > environments.
>>
>> The problems are not restricted to differences between C++
>> compilers and versions, but are also made worse by the normal
>> recommended C++ programming idiom where the sizes of all
>> objects are exposed through the .h files to the users of your
>> libraries who will put them on the stack, make arrays of them,
>> subclass them and generally do things that mean you can never
>> ever add as much as one single private member variable without
>> breaking binary compatibility with your old library versions.
>>
>> There are ways around this 'fragile base class' problem, of
>> course, where you put all the data in a separate object, or
>> make sure you have enough padding in your classes for future
>> expansion, but C++ doesn't actively support this way of doing
>> things, or check that you don't accidentally get it wrong.
>>
>> Qt and Be's libraries suffer from this. I imagine any C++-based
>> library will.
> But without separating implementation from interface, how do you do
> this?
You don't.
> Sure, such separation is generally a good thing, only it costs.
Virtual methods are also a good thing, but they cost, so C++
made them optional, so perhaps it should be an optional feature
of a class. Something like
class interface C {
...
}
which signals to the compiler that this class is to be used
in the externally visible interface in a DLL and binary
compatibility across versions is desired. That probably
means moving all private data members into a separate
autoallocated indirected area and prohibiting public and
protected data members. Then you would issue errors for
inlined and non-virtual methods, and use a hashed lookup for
virtual methods to make sure the right one gets called even if
a later implementation reorders or adds methods (even adding is
dangerous if the class is subclassed with the present system).
Perhaps the run-time linker can do something clever and
efficient instead here.
Even a more minimal feature like:
class padded 256 vmt 32 C {
...
}
that automatically padded my sizeof up to 256, padded the
virtual method table to 32 and warned me if I exceeded those
limits would make the pad-your-objects-presciently method more
manageable without having to do horrendous manipulations with
sizeof and macros.
> C++ classes can efficiently represent quite small things - when you add
That's great, but not usually for the interface of a DLL.
> the level of indirection necessary to separate interface from
> implementation then you get "proper OO", but you need coarse granularity
> of objects to run at the same speed. C++ was never intended to do what
> you're asking of it - if you want that, use another language.
What you are saying is that C++ is unsuitable for implementing
DLLs or shared libraries. That's almost true, but that's a huge
area to cut it off from.
This isn't some niche application, shared libraries are everywhere.
Breaking each time a private data member is added is not an option.
> If you want speed, use C++
Ah, but what if I want speed, robustness and O-O in my shared
library/DLL? Is C++ the wrong language, or do I have to be
incredibly disciplined and foresightful and cannot rely on
the compiler telling me when I screw up.
--
Erik Corry erik@arbat.com
next prev parent reply other threads:[~1999-05-06 4:00 UTC|newest]
Thread overview: 124+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-03-13 5:00 Did Intel pay UGS to kill Alpha port? Or Compaq simply doesn't care? N Novakovic
1999-03-14 5:00 ` Compiler for Alpha/Linux (Re: " News Man
1999-03-15 5:00 ` Chris Petersen
1999-03-15 5:00 ` Clint Comes
[not found] ` <36EEE5F6.69F7@world.std.com>
[not found] ` <7cog3r$hj8$1@plonk.apk.net>
1999-03-21 5:00 ` N Novakovic
1999-03-20 5:00 ` Terry C. Shannon
1999-03-20 5:00 ` Robert Harley
1999-03-20 5:00 ` Zalman Stern
1999-03-21 5:00 ` Jan Vorbrueggen
1999-03-22 5:00 ` Zalman Stern
1999-03-23 5:00 ` N Novakovic
1999-03-25 5:00 ` Cameron Laird
1999-04-08 4:00 ` Jan Vorbrueggen
1999-04-08 4:00 ` John Stone
1999-04-08 4:00 ` Ian Kemmish
1999-04-09 4:00 ` Steven J. Luther
1999-04-09 4:00 ` Terry C Shannon
1999-04-08 4:00 ` Jan Vorbrueggen
1999-04-08 4:00 ` Andy Glew
1999-04-10 4:00 ` Jeff Kenton
1999-04-12 4:00 ` Maynard Handley
1999-04-12 4:00 ` Andrew Reilly
1999-04-13 4:00 ` Andy Freeman
1999-04-13 4:00 ` Jan Vorbrueggen
1999-04-13 4:00 ` Andy Freeman
1999-04-14 4:00 ` Zalman Stern
1999-04-14 4:00 ` Andy Freeman
1999-04-16 4:00 ` Maynard Handley
1999-04-13 4:00 ` Zalman Stern
1999-04-13 4:00 ` TTK Ciar
1999-04-14 4:00 ` Zalman Stern
1999-04-14 4:00 ` Jan Gray
1999-04-14 4:00 ` TTK Ciar
1999-04-14 4:00 ` Larry Kilgallen
1999-04-24 4:00 ` Exception handling Daniel P. B. Smith
1999-04-24 4:00 ` Zalman Stern
1999-04-24 4:00 ` Daniel P. B. Smith
1999-04-25 4:00 ` Zalman Stern
1999-04-25 4:00 ` Andi Kleen
1999-04-25 4:00 ` Erik Corry
1999-05-06 4:00 ` Greg Law
1999-05-06 4:00 ` Zalman Stern
1999-05-06 4:00 ` Erik Corry [this message]
1999-04-13 4:00 ` Did Intel pay UGS to kill Alpha port? Or Compaq simply doesn't care? Larry Kilgallen
1999-04-13 4:00 ` Zalman Stern
1999-04-16 4:00 ` Maynard Handley
1999-04-16 4:00 ` Zalman Stern
1999-04-19 4:00 ` Eric Hildum
1999-04-18 4:00 ` Samuel Paik
1999-04-19 4:00 ` Ketil Z Malde
1999-04-19 4:00 ` Fred Kleinsorge
1999-04-22 4:00 ` dejadan7
1999-04-23 4:00 ` Adam Price
1999-04-18 4:00 ` Exceptions, Error codes, and Wrappers Andy Glew
1999-04-19 4:00 ` Hoff Hoffman
1999-04-14 4:00 ` Did Intel pay UGS to kill Alpha port? Or Compaq simply doesn't care? TTK Ciar
[not found] ` <F9zI7t <371ACB9F.F9A9710@webnexus.com>
1999-04-19 4:00 ` Martin Vorlaender
1999-04-20 4:00 ` Samuel Paik
1999-04-10 4:00 ` TTK Ciar
1999-04-12 4:00 ` Jan Vorbrueggen
1999-04-12 4:00 ` Maynard Handley
1999-04-12 4:00 ` Peter da Silva
1999-04-12 4:00 ` Jan Vorbrueggen
1999-04-13 4:00 ` N Novakovic
1999-04-16 4:00 ` Peter Mayne
1999-04-16 4:00 ` Zalman Stern
1999-04-16 4:00 ` Zalman Stern
1999-04-19 4:00 ` Peter Mayne
1999-04-20 4:00 ` Zalman Stern
1999-04-12 4:00 ` TTK Ciar
1999-03-21 5:00 ` Anil T Maliyekke
1999-03-22 5:00 ` Chris Petersen
1999-03-22 5:00 ` Chris Petersen
1999-03-25 5:00 ` Jeff and Beth Donsbach
1999-04-08 4:00 ` Jan Vorbrueggen
1999-03-22 5:00 ` John Aldridge
1999-03-23 5:00 ` N Novakovic
1999-03-23 5:00 ` Network effect (was Re: Did Intel pay UGS to kill Alpha port?...) Steven Correll
1999-03-24 5:00 ` Maynard Handley
1999-03-24 5:00 ` Jeffrey J. Potoff
1999-03-25 5:00 ` Maynard Handley
1999-03-25 5:00 ` Aaron Spink
1999-03-26 5:00 ` Auto Security (was Re: Network effect (was Re: Did Intel pay UGS to kill Alpha port?...)) Chris
1999-03-25 5:00 ` Network effect (was Re: Did Intel pay UGS to kill Alpha port?...) Pete Zaitcev
1999-03-25 5:00 ` Maynard Handley
1999-03-25 5:00 ` Jeffrey J. Potoff
1999-03-25 5:00 ` Peter Seebach
1999-03-25 5:00 ` Consumers Reports (was: Network effect ...) Dennis O'Connor
1999-03-26 5:00 ` Peter Seebach
1999-03-26 5:00 ` Zalman Stern
1999-03-26 5:00 ` Network effect (was Re: Did Intel pay UGS to kill Alpha port?...) Terry C. Shannon
1999-03-25 5:00 ` Alan Frisbie
1999-03-25 5:00 ` Rob Rodgers
1999-03-25 5:00 ` Patrick F. McGehearty
1999-03-26 5:00 ` Pete Zaitcev
1999-03-26 5:00 ` Peter da Silva
1999-03-29 5:00 ` Joe Pfeiffer
1999-03-25 5:00 ` George Cornelius
1999-03-26 5:00 ` Larry Kilgallen
1999-03-26 5:00 ` Allen J. Baum
1999-03-27 5:00 ` Larry Kilgallen
1999-03-24 5:00 ` Terry C. Shannon
1999-03-27 5:00 ` Larry D Bohan, Jr
1999-03-27 5:00 ` JohnC
1999-03-28 5:00 ` Larry D Bohan, Jr
1999-03-28 5:00 ` Gary Heston
1999-03-28 5:00 ` Peter da Silva
1999-03-24 5:00 ` Bruce Hoult
1999-03-24 5:00 ` Peter Seebach
1999-03-24 5:00 ` Terry C. Shannon
1999-03-24 5:00 ` Toon Moene
1999-03-27 5:00 ` Mark
1999-03-27 5:00 ` Resistance must organize (was Re: Network effect Paul DeMone
1999-03-27 5:00 ` Mark
1999-03-28 5:00 ` Usenet formatting (was Re: Resistance must organize) Bengt Larsson
1999-03-28 5:00 ` John Moreno
1999-03-28 5:00 ` Mark
1999-03-30 5:00 ` Bengt Larsson
1999-03-30 5:00 ` Zalman Stern
1999-03-30 5:00 ` Bengt Larsson
1999-03-30 5:00 ` Mark Rogers
1999-04-01 5:00 ` Eric Hildum
1999-03-31 5:00 ` John Moreno
1999-03-30 5:00 ` Network effect (was Re: Did Intel pay UGS to kill Alpha port?...) Joe Keane
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox