Class size change in a DLL/so

H

Hovik Melikyan

I'm trying add a new member to a class that's defined and implemented
in a dynamic library (both Windows DLL and Unix SO). Provided that I
don't change the interface methods and I add this new member field to
the end of the class, will old programs linked against this DLL/so
work with the new version of the dynamic library without
recompilation?

Also: the constructor is not inlined and I'm not going to add new
virtual methods.

(While this is dangerous, of course, but I suspect it is still
possible...)

Thanks,
 
I

Ivan Vecerina

Hovik Melikyan said:
I'm trying add a new member to a class that's defined and implemented
in a dynamic library (both Windows DLL and Unix SO). Provided that I
don't change the interface methods and I add this new member field to
the end of the class, will old programs linked against this DLL/so
work with the new version of the dynamic library without
recompilation?

Also: the constructor is not inlined and I'm not going to add new
virtual methods.

(While this is dangerous, of course, but I suspect it is still
possible...)

Only if the objects are always allocated on the heap,
and created/deleted by the DLL.

Best would probably be to study existing systems that have
implemented this type of flexible mechanism.
MS COM, Mozilla's XPCOM, and BeOS (different approach)
come to mind. You'll see what the limitations/workarounds are.
You can also google for "fragile base class" to learn more
about this topic...


hth - Ivan
 
M

Mike Smith

Hovik said:
I'm trying add a new member to a class that's defined and implemented
in a dynamic library (both Windows DLL and Unix SO). Provided that I
don't change the interface methods and I add this new member field to
the end of the class, will old programs linked against this DLL/so
work with the new version of the dynamic library without
recompilation?

Also: the constructor is not inlined and I'm not going to add new
virtual methods.

(While this is dangerous, of course, but I suspect it is still
possible...)

Adding new data members or virtual functions is probably going to bite
you eventually, but adding non-virtual functions will probably work.
 
E

E. Robert Tisdale

Hovik said:
I'm trying add a new member to a class that's defined and implemented
in a dynamic library (both Windows DLL and Unix SO).
Provided that I don't change the interface methods
and I add this new member field to the end of the class,
will old programs linked against this DLL/so
work with the new version of the dynamic library
without recompilation?

No!
The old programs will *not* reserve the extra memory
required for the new data member.
Also: the constructor is not inlined
and I'm not going to add new virtual methods.

(While this is dangerous, of course,
I suspect it is still possible...)

Just derive a *new* class from the old class
and add the new data member to the derived class.
Just remember that the old programs are going to use
the old class definition if they need to create objects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top