On Mon, 14 Mar 2005, I wrote:
Of course, taking the cl_heap* part of a cl_heap_modint_ring* results in an offset the size of the vptr. And for it to work it's required that the definitions are visible. Otherwise the offset will be zero.
However, if one takes care that the pointer of a cl_rcpointer always points to the cl_heap sub-part, one runs into serious trouble later. In src/base/cl_free.cc: void cl_free_heap_object (cl_heap* pointer) { // This is invoked when pointer->refcount gets decremented to 0. var const cl_class* type = pointer->type; if (type->destruct) type->destruct(pointer); free_hook(pointer); } This calls only the registered dtor of the subobject, which invokes undefined behavior! (In practice, "undefined" means a downright segfault, in this case.) I see no way to cure this problem without adding more indirection. The best idea I'm currently having is removing the vptr from all classes derived from cl_heap. This is done in the attached patch. It makes each subclass of cl_heap_modint_ring have different cl_class* type, however, so they cannot be compared any more! For this reason, it is best to remove the extern declaration of the static cl_class_modint_ring and rely on cl_class::flags for run time type information. (There goes a clear design.) If somebody wants to bang on the patch, I'm interested in hearing how it goes. -richy. -- Richard B. Kreckel <http://www.ginac.de/~kreckel/>