Function pointer casts


I am reading the GPtrArray code (in glib/glib/garray.c) from Git.  I noticed this code in g_ptr_array_sort():

g_ptr_array_sort (GPtrArray    *array,
                  GCompareFunc  compare_func)
  g_return_if_fail (array != NULL);

  /* Don't use qsort as we want a guaranteed stable sort */
  g_qsort_with_data (array->pdata,
                     sizeof (gpointer),

This code casts GCompareFunc to GCompareDataFunc.  As I understand, casting function pointers in C is not allowed.

I am happy to post a patch if others are in agreement.  However, since I am new to hacking GLib & GTK+, perhaps there are good historical/technical reasons to cast function pointers as above.  If so, please explain.

I would like to add a test if compare_func is NULL.  This seems strange that we allow compare_func to be NULL here.  Again, if this is a bad idea, please tell me.  (Same also for g_ptr_array_sort_with_data().)

I checked the g_qsort_with_data() code.  There is also no check if compare_func is NULL -- or any other params

P.S. I just realised today that I have been incorrectly sending dev-style mails to gtk-list gnome org.  Apologies if I annoyed anyone(!).

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]