Fragile virtual functions

Michel Fortin michel.fortin at michelf.com
Sat Mar 8 10:30:05 PST 2008


On 2008-03-08 07:59:38 -0500, "Janice Caron" <caron800 at googlemail.com> said:

> If a class changes (or a struct, or an enum, or a typedef, or a
> template, or ... /anything/ ...) then anything which uses it must be
> recompiled. That's just how it works.
> 
> Most people have a build system to automate this. (make, dsss,
> whatever). It's not hard. Basically you just rebuild all the
> dependencies.

I know you can just recompile everything and it'll work, but I'm 
wondering about how to provide a stable API in a dynamic library which 
can stay compatible even when a client application isn't recompiled.

You can add new functions, new types, etc. to a module and keep the 
binary compatibility, but adding, or just reordering, member functions 
of a class break that compatiblity and I wondered if this could be 
mitigated with the way I suggested it.

As a counter-example, take an Objective-C API: you can add member 
functions as much as you like, even reorder them in the source code, 
and you'll keep binary compatibility in a library. It's no wonder why 
Apple prefers to not expose C++ API for their operating system. They 
use C++ internally for many things (you know when you get a stack 
trace), but they don't expose that.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list