简体   繁体   English

为什么qsort通过使用typedef枚举在gcc 6.3.0中导致错误?

[英]Why qsort cause error in gcc 6.3.0 by using typedef enum?

I'm working for Strongly Connected Component (SCC) algorithm. 我正在为强连接组件(SCC)算法工作。

So, I sorted vertices by increasing order using qsort function. 因此,我使用qsort函数通过增加顺序对顶点进行了排序。

To use qsort , I made my own compare function and used typedef enum{false,true} bool . 要使用qsort ,我制作了自己的比较函数,并使用了typedef enum{false,true} bool

VS2017 IDE compiles successfully of this but MinGW which has gcc 6.3.0 cause error like below. VS2017 IDE对此进行了成功编译,但是具有gcc 6.3.0的MinGW导致如下错误。

在此处输入图片说明

My CreateSorted and qsort compare function are these codes. 这些代码是我的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;
}

What I really curious is the reason of error resulting from typedef enum{false, true} bool . 我真正好奇的是typedef enum{false, true} bool导致错误的原因。

The fourth parameter to qsort should be a pointer to a function with the following prototype: qsort的第四个参数应该是具有以下原型的函数的指针:

int compar (const void* p1, const void* p2)

The prototype of your function is: 函数的原型是:

bool compar (const void* p1, const void* p2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM