错误类型冲突

标签 c types

我正在使用数组实现处理优先级队列。一切似乎都正常,但我收到此错误:'remove' 的冲突类型 我已经在它的头文件中声明了这个函数,我已经包含了头文件但是编译器仍然提示。我认为问题出在其他地方。

这里是 pqueue.h:

    #ifndef PQUEUE_H
    #define PQUEUE_H
    //---------------

    #define HIGHP  0
    #define MEDP   1
    #define LOWP   2
    #define MAXEL 10

    #include <stddef.h>

    typedef struct message {
        char data[100];
        int priority;
    } message;

    typedef struct pQueue {
        struct message messages[10];
        int rear;
        int front;
        int size;
    } pQueue;

    void initPQueue(pQueue *pq);
    void add(pQueue *pq, char *data, int pri);
    char* remove(struct pQueue *pq);    // Error: conflicting types for: 'remove'
    int isEmpty(pQueue *pq);

    #endif

pqueue.c:

    #include "pqueue.h"
    #include <string.h>

    void initPQueue(pQueue *pq) {
        pq->front = 0;
        pq->rear = 0;
        pq->size = 0;
    }

    void add(pQueue *pq, char *data, int pri) {
        if (pq->size > MAXEL) {
            return; // NOTE: data is lost
        }
        message m;
        strcpy(m.data, data);
        m.priority = pri;

        if (isEmpty(pq)) {
            pq->messages[pq->rear] = m;
            pq->rear = (pq->rear % (MAXEL - 1)) + 1;
            return; // done
        }

        /**TODO: NEEDS REPAIR**/
        int i = 0;
        int j = 0;
        for (; i < pq->rear; i = (i % (MAXEL - 1)) + 1) {
            if (m.priority > pq->messages[i].priority) {
                // found element with higher or equal priority
                for (j = pq->rear - 1; j >= i; j = (j % (MAXEL - 1)) - 1) {
                    pq->messages[j] = pq->messages[j - 1];
                }
                    break;
            }
        }
        pq->messages[i] = m;
        /****/

        pq->size++;
    }

    char* remove(struct pQueue *pq) {
        if (isEmpty(pq)) {
            return NULL ;
        }
        pq->size--;
        return pq->messages[pq->front].data;
    }

    int isEmpty(pQueue *pq) {
        if (!pq->size) 
            return 1;

        return 0;
    }

有什么想法吗?

最佳答案

int remove(const char *path) 是一个标准函数。您需要为自己选择一个不同的名称。

关于错误类型冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13330394/

相关文章:

c - fscanf 函数如何工作?

ios - 一个类继承另一个类并遵守一个协议(protocol)——试图调和两个​​接口(interface)

scala - 使用递归类型的基本 Scala 反射代码无法编译。为什么 ?如何解决?

C从控制台读取限制字符输入。怎么办?

java - scala 使用内部类和类型参数覆盖 java 类方法

types - async fn 的类型是什么?

c - C中整数到 float 的转换

c - 使用递归的解决方案数量

c++ - 实现最速下降算法,可变步长

从 C 调用 Swift