GLib树插入始终插入同一节点 [英] GLib tree insertion always inserts in the same node
本文介绍了GLib树插入始终插入同一节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一段非常简单的代码
I have this very simple piece of code
GTree* teste = g_tree_new(cmp);
for(int i = 0; i < 10; i++){
g_tree_insert(teste, &i, &i);
printf("%d", g_tree_nnodes(teste));
}
"cmp"功能是
int cmp(const void *a, const void* b){
int* ia = (int*)a;
int* ib = (int*)b;
return (*ia - *ib);
}
我不明白为什么,但是节点数始终是一个.似乎比较函数未正确使用,并且始终断言为0.
I don't understand why, but the number of nodes is always one. It seems the compare function is not being used properly, and it always asserts to 0.
推荐答案
查看全文