Bob Jamison wrote:
These have long been irritating. Maybe someone could just instantiate these guys, get the offests, and discard. Wasteful, but cleaner.
display/canvas-arena.cpp:85: warning: invalid access to non-static data member `SPCanvasArenaClass::arena_event' of NULL object display/canvas-arena.cpp:85: warning: (perhaps the `offsetof' macro was used incorrectly) display/sp-canvas.cpp:132: warning: invalid access to non-static data member `SPCanvasItemClass::event' of NULL object display/sp-canvas.cpp:132: warning: (perhaps the `offsetof' macro was used incorrectly)
Apparently not. It seems that g++ will issue this warning whenever offsetof() or GTK_SIGNAL_OFFSET() are used.
GTK_SIGNAL_OFFSET and GTK_STRUCT_OFFSET are based on this declaration:
#define G_STRUCT_OFFSET(struct_type, member) \ ((glong) ((guint8*) &((struct_type*) 0)->member))
Here is a gcc mailing list item regarding this: http://gcc.gnu.org/ml/gcc/2003-11/msg00279.html
To be a POD struct, there must not be any virtual members. I guess that the function pointers make the classes in question virtual.
===========================
struct SPCanvasArenaClass { SPCanvasItemClass parent_class;
gint (* arena_event) (SPCanvasArena *carena, NRArenaItem *item, GdkEvent *event); };
struct SPCanvasItemClass : public GtkObjectClass { void (* update) (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
void (* render) (SPCanvasItem *item, SPCanvasBuf *buf); double (* point) (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item);
int (* event) (SPCanvasItem *item, GdkEvent *event); };
=========================== I had hoped that something like
glong offset = (glong) (&(obj->arena_item) - obj);
would work, but apparently g++ catches that sneaky method also.
Can anyone think of anything?
The Apache module C api avoids this, by actually having a table that switches the calls to the redefinable functions characterizing the class.
Or maybe this is just legacy, and needs to be recast in libsigc++?
bob