I'm trying to build a project in Xcode but I get the following errors Implicit declaration of function 'clear' is invalid in C99
and Conflicting types for 'clear'
.
Here's the code:
//main.c
#include <stdio.h>
#include "tree.h"
int main(){
clear(); // Implicit declaration of function 'clear' is invalid in C99
return 0;
}
//tree.c
#include <stdio.h>
#include "tree.h"
void clear(){ ///Conflicting types for 'clear'
printf("Command clear.
");
}
//tree.h
#include <stdio.h>
void clear(); ///Conflicting types for 'clear'
Why do I get these errors and warnings? I've tried to search for the solution on StackOverflow, but all the related answers where about the case when there were no #include
of some sort.
'clear' is not a keyword in C so it's not the case, is it?
(source: http://aboutc.weebly.com/keywords.html)
Related topics (do not answer my question although they are actually related):
Thanks for any help.
UPDATE!
It turns out that changing the name of the clear
funtcion to a cleark
function solved the problem. Nevertheless it does not make any sense to me yet.
UPDATE 2!
I based my project on the command line tool
template from Xcode 6.3 on Mac OS 10.10. Because of that Xcode has automatically added some libraries and flags to the project's compiler. What's the most important here is that the curses.h
header has been added and this header already contains the clear()
function.
Here's the Conflicting types for 'clear'
error log:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/curses.h:541:28: Previous declaration is here
I've tried to remove the -lcurses
from the compiler's flags manually, but I couldn't locate such settings. Is there any another way to build the project? (All in all my goal is to be able to use the Xcode's debugger when the project expands)
UPDATE 3!
According to what Paul Griffiths discovered and published in the comment below the problem is following:
I can indeed replicate this problem with Xcode 6.3.1 with only the code presented. For some reason, stdio.h seems to be including curses.h (i.e. if you don't include stdio.h, this issue goes away), and I haven't been quickly able to find a way to stop it doing that. This seems to be problematic, since standard headers should not import random symbols into the global namespace without an easy and obvious way to turn it off.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…