'C: conflicting types error
I want to check a linked List of Elements holding an Integer each, if a value is already inside.
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;
}
}
Im getting a conflicting types for the checkCurrent Method, but can't find it.
Solution 1:[1]
Is missing the function declaration. In C, you need to declare the function, exactly as it is.
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;
}
}
Solution 2:[2]
checkCurrent() is used before it is declared, or defined, which results in an implicit function declaration being generated with a return type of int (which is not the same as the definition of the function which has return type bool). Add a declaration for checkCurrent() prior to its first use:
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);
}
or move its definition prior to checkForInt().
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Carlos Irano |
| Solution 2 |
