typedef struct s_variable { char *name; int start; int end; int reg; int overlaps; gboolean reassigned; } variable; gint varcmp(gconstpointer a, gconstpointer b) { variable *x = (variable *)a; variable *y = (variable *)b; if (x->end < y->end) return -1; else if (x->end == y->end) return 0; return 1; } gboolean make_tree(gpointer key, gpointer value, gpointer data) { variable *var = (variable *)value; GTree *t = (GTree *)data; printf("Adding %s(end=%d) to the tree %p", var->name, var->end, t); g_tree_insert(t, var->name, var); printf(" (%d)\n", g_tree_nnodes(t)); return TRUE; } GTree *t = g_tree_new(varcmp); printf("Tree is at %p\n",t); g_hash_table_foreach(vars, make_tree, t); printf("Tree now has %d elements\n", g_tree_nnodes(t)); /* output: Tree is at 0x804df70 Adding $five(end=6) to the tree 0x804df70 (1) Adding $one(end=2) to the tree 0x804df70 (1) Adding $two(end=3) to the tree 0x804df70 (1) Adding $six(end=7) to the tree 0x804df70 (1) Adding $three(end=4) to the tree 0x804df70 (1) Adding $four(end=5) to the tree 0x804df70 (1) Adding $seven(end=8) to the tree 0x804df70 (1) Adding $ten(end=11) to the tree 0x804df70 (1) Adding $zero(end=1) to the tree 0x804df70 (1) Adding $nine(end=10) to the tree 0x804df70 (1) Adding $eight(end=9) to the tree 0x804df70 (1) Tree now has 1 elements */