[英]implicit declaration of function ‘getChar’ in C
Some I have this error when I try to compile a program in C. 有些人在尝试用C编译程序时遇到此错误。
myfunctions.c:27:2: warning: implicit declaration of function ‘getChar’ [-Wimplicit-function-declaration]
Here is line 27: 这是第27行:
while(myChar = getChar() && myChar != '')
I'm calling this in the header: 我在标题中称呼它为:
#include <stdio.h>
#include <unistd.h>
It's spelled getchar
, not getChar
. 它的拼写是getchar
,而不是getChar
。 C is case sensitive, and pretty much all the standard C functions' names are all lowercase. C是区分大小写的,几乎所有标准C函数的名称都是小写的。
As for why it's "implicitly declared" when it doesn't exist...in older versions of C, if a function name isn't known to the compiler, it's assumed to be a function that returns an int
. 至于为什么它不存在时被“隐式声明”的原因……在较旧的C版本中,如果编译器不知道函数名,则假定它是一个返回int
的函数。 It's almost as if you said int getChar();
几乎就像您说的是int getChar();
. 。 I hear C99 doesn't allow this, but most compilers don't stick to it anyway unless you tell them to. 我听说C99不允许这样做,但是除非您告诉他们,否则大多数编译器还是不会坚持这样做。
I don't know why, but GCC compiler (win platform) knows getch()
. 我不知道为什么,但是GCC编译器(win平台)知道getch()
。 But if you switch on -pedantic
compilation, than this warning occurs. 但是,如果打开-pedantic
编译,则会出现此警告。
Solution: use getchar()
and everything should work ok. 解决方案:使用getchar()
,一切应该正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.