繁体   English   中英

C:冲突类型错误

[英]C: conflicting types error

我想检查一个链接的元素列表,每个元素都包含一个整数,如果一个值已经在里面。

struct ListenElement{
    int wert;
    struct ListenElement *nachfolger;
};

struct ListenAnfang{
    struct ListenElement *anfang;
};

struct ListenAnfang LA;

bool ckeckForInt(int value){
    if (LA.anfang == NULL){
        return 0;
    }
    return checkCurrent(LA.anfang, value);
}

bool checkCurrent(struct ListenElement* check, int value){
    if (check->wert == value){
        return true;
    }
    else if (check->nachfolger != NULL){
        return checkCurrent(check->nachfolger, value);
    }
    else{
        return false;
    }   
}

我得到checkCurrent方法的冲突类型,但找不到它。

checkCurrent() 声明或定义之前使用,这会导致生成一个返回类型为int的隐式函数声明(与返回类型为bool的函数的定义不同)。 在第一次使用之前为checkCurrent()添加声明:

bool checkCurrent(struct ListenElement* check, int value);

bool ckeckForInt(int value){
    if (LA.anfang == NULL){
        return false; /* Changed '0' to 'false'. */
    }
    return checkCurrent(LA.anfang, value);
}

或者在checkForInt()之前移动它的定义。

缺少函数声明。 在C中,您需要完全按原样声明函数。

struct ListenElement{
    int wert;
    struct ListenElement *nachfolger;
};

struct ListenAnfang{
    struct ListenElement *anfang;
};

struct ListenAnfang LA;

//The function declaration !
bool checkCurrent(struct ListenElement* check, int value);

bool ckeckForInt(int value){
    if (LA.anfang == NULL){
        return 0;
    }
    return checkCurrent(LA.anfang, value);
}

bool checkCurrent(struct ListenElement* check, int value){
    if (check->wert == value){
        return true;
    }
    else if (check->nachfolger != NULL){
        return checkCurrent(check->nachfolger, value);
    }
    else{
        return false;
    }   
}

暂无
暂无

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

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