diff options
author | Will Thompson <will@willthompson.co.uk> | 2018-06-08 13:29:42 +0100 |
---|---|---|
committer | Will Thompson <will@willthompson.co.uk> | 2018-06-08 13:31:09 +0100 |
commit | a5999623dee5ac698308524219cae250c3163bdd (patch) | |
tree | c622e30bfb3195baa6f4beba103ed66b75f5c75c | |
parent | aa44ece68435e94b408a8f9826c65938414f2305 (diff) | |
download | glib-G_SOURCE_FUNC-macro.tar.gz |
Add G_SOURCE_FUNC cast macro which suppresses -Wcast-function-typeG_SOURCE_FUNC-macro
This is the workaround suggested by
https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wcast-function-type
This warning is not enabled by default during the GLib build, but
applications may want to opt into it.
-rw-r--r-- | glib/gmain.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/glib/gmain.h b/glib/gmain.h index 2515d7326..fa2abf5ea 100644 --- a/glib/gmain.h +++ b/glib/gmain.h @@ -169,6 +169,21 @@ typedef struct _GSourceFuncs GSourceFuncs; typedef gboolean (*GSourceFunc) (gpointer user_data); /** + * G_SOURCE_FUNC: + * @f: a function pointer. + * + * Cast a function pointer to a #GSourceFunc, suppressing warnings from recent + * versions of GCC about the function types being incompatible. + * + * For example, the correct type of callback for a source created by + * g_child_watch_source_new() is #GChildWatchFunc, which accepts more arguments + * than #GSourceFunc. Casting it with `(GSourceFunc)` to call + * g_source_set_callback() will trigger a warning, even though it will be cast + * back to the correct type before it is called by the source. + */ +#define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f)) + +/** * GChildWatchFunc: * @pid: the process id of the child process * @status: Status information about the child process, encoded |