[英]Why qsort cause error in gcc 6.3.0 by using typedef enum?
我正在為強連接組件(SCC)算法工作。
因此,我使用qsort
函數通過增加順序對頂點進行了排序。
要使用qsort
,我制作了自己的比較函數,並使用了typedef enum{false,true} bool
。
VS2017 IDE對此進行了成功編譯,但是具有gcc 6.3.0的MinGW導致如下錯誤。
這些代碼是我的CreateSorted
和qsort
比較函數。
// qsort compare function, descending order
bool cmp(const void *p1, const void *p2)
{
VF* vf1 = (VF*)p1;
VF* vf2 = (VF*)p2;
return vf2->f - vf1->f;
}
// Create sorted vertices array of VF structure
// For DFS of decreasing finish time vertex
VF* CreateSorted(adjList* adj)
{
VF *sorted_vertices = (VF*)malloc(sizeof(VF)*(adj->vertexNum+1));
for (int i = 1; i <= adj->vertexNum; i++) {
Node* current = adj[i].nodeList;
sorted_vertices[i].v = current->v;
sorted_vertices[i].f = current->f;
}
qsort(sorted_vertices+1, adj->vertexNum, sizeof(VF), cmp);
return sorted_vertices;
}
我真正好奇的是typedef enum{false, true} bool
導致錯誤的原因。
qsort
的第四個參數應該是具有以下原型的函數的指針:
int compar (const void* p1, const void* p2)
函數的原型是:
bool compar (const void* p1, const void* p2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.