W
WaterWalk
*Hope this thread doesn't violate this group's rule*
I found the following code in the GNOME's glib-2.12 source:
/* In gclosure.c */
GClosure*
g_cclosure_new (GCallback callback_func,
gpointer user_data,
GClosureNotify destroy_data)
{
......
/* ((GCClosure*) closure)->callback is of type gpointer */
((GCClosure*) closure)->callback = (gpointer) callback_func;
}
Here a GCallback is cast to a gpointer type. The definition of
GCallback and gpointer are as follows:
typedef void (*GCallback) (void); /* in gclosure.h */
typedef void* gpointer; /* in gtypes.h */
So the result is that a (void (*)(void)) is cast to (void*). However a
search of this group and c99 standard indicates that casting a
function pointer to a void pointer is undefined behavior. I wonder if
the glib practice is preferable.
I found the following code in the GNOME's glib-2.12 source:
/* In gclosure.c */
GClosure*
g_cclosure_new (GCallback callback_func,
gpointer user_data,
GClosureNotify destroy_data)
{
......
/* ((GCClosure*) closure)->callback is of type gpointer */
((GCClosure*) closure)->callback = (gpointer) callback_func;
}
Here a GCallback is cast to a gpointer type. The definition of
GCallback and gpointer are as follows:
typedef void (*GCallback) (void); /* in gclosure.h */
typedef void* gpointer; /* in gtypes.h */
So the result is that a (void (*)(void)) is cast to (void*). However a
search of this group and c99 standard indicates that casting a
function pointer to a void pointer is undefined behavior. I wonder if
the glib practice is preferable.