#include <stdio.h>
#include <glib.h>

static gboolean a_depends_on_b(const char *a, const char *b)
{
    /* a=A depends on b=C */
    if (!g_strcmp0(a, "A") && !g_strcmp0(b, "C"))
        return TRUE;
    return FALSE;
}

int my_func(const char *a, const char *b)
{
    printf("Compare %s to %s\n", a, b);
    if (a_depends_on_b(a, b))
        return 1; /* return >0 as b < a as per dependency */
    else if (a_depends_on_b(b, a))
        return -1; /* return <0 as a < b as per dependency */

    else return strcmp(a, b);
}

int main()
{
    GList *list = NULL;

    list = g_list_append(list, "A");
    list = g_list_append(list, "B");
    list = g_list_append(list, "C");

    list = g_list_sort(list, (GCompareFunc)my_func);

    /* since A depends on C, B must come first */
    g_list_foreach(list, (GFunc)puts, NULL);
}
