簡體   English   中英

為什么qsort通過使用typedef枚舉在gcc 6.3.0中導致錯誤?

[英]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導致如下錯誤。

在此處輸入圖片說明

這些代碼是我的CreateSortedqsort比較函數。

// 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM